From a7077a7745ad67caf3fa26800855eef8eb517be8 Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 15 Sep 2022 00:03:59 +0200 Subject: [PATCH 1/2] Bump toolchain to `nightly-2022-09-14` --- .../hash_graph/lib/graph/src/api/rest/mod.rs | 23 ++++++++++--------- .../graph/hash_graph/lib/graph/src/lib.rs | 2 -- .../hash_graph/lib/graph/src/logging/init.rs | 17 +++++++++----- .../hash_graph/lib/graph/src/store/pool.rs | 4 +--- .../src/store/postgres/context/entity.rs | 4 +++- .../graph/src/store/postgres/context/links.rs | 4 +++- .../src/store/postgres/context/ontology.rs | 4 +++- packages/graph/hash_graph/rust-toolchain.toml | 3 ++- 8 files changed, 35 insertions(+), 26 deletions(-) diff --git a/packages/graph/hash_graph/lib/graph/src/api/rest/mod.rs b/packages/graph/hash_graph/lib/graph/src/api/rest/mod.rs index d3324753865..c3f2631e85e 100644 --- a/packages/graph/hash_graph/lib/graph/src/api/rest/mod.rs +++ b/packages/graph/hash_graph/lib/graph/src/api/rest/mod.rs @@ -146,17 +146,18 @@ pub fn rest_api_router( async fn serve_static_schema(Path(path): Path) -> Result { let path = path.trim_start_matches('/'); - match STATIC_SCHEMAS.get_file(path) { - None => Err(StatusCode::NOT_FOUND), - Some(file) => Ok(( - [( - axum::http::header::CONTENT_TYPE, - axum::http::HeaderValue::from_static("application/json"), - )], - file.contents(), - ) - .into_response()), - } + STATIC_SCHEMAS + .get_file(path) + .map_or(Err(StatusCode::NOT_FOUND), |file| { + Ok(( + [( + axum::http::header::CONTENT_TYPE, + axum::http::HeaderValue::from_static("application/json"), + )], + file.contents(), + ) + .into_response()) + }) } #[derive(OpenApi)] diff --git a/packages/graph/hash_graph/lib/graph/src/lib.rs b/packages/graph/hash_graph/lib/graph/src/lib.rs index 43b3b0e7575..6f018ec71e6 100644 --- a/packages/graph/hash_graph/lib/graph/src/lib.rs +++ b/packages/graph/hash_graph/lib/graph/src/lib.rs @@ -4,8 +4,6 @@ #![feature(lint_reasons)] // Not required, reason: Use `std` feature rather than external crate #![feature(once_cell)] -// Not required, reason: Easier than having a separated trait with lifetime bounds -#![feature(generic_associated_types)] // Not required, reason: Simpler than using blanket implementations #![feature(trait_alias)] // Not required, reason: much more simple bounds diff --git a/packages/graph/hash_graph/lib/graph/src/logging/init.rs b/packages/graph/hash_graph/lib/graph/src/logging/init.rs index 5110d49d046..c76ce595b26 100644 --- a/packages/graph/hash_graph/lib/graph/src/logging/init.rs +++ b/packages/graph/hash_graph/lib/graph/src/logging/init.rs @@ -60,12 +60,17 @@ pub fn init_logger>( let log_folder = log_folder.as_ref(); let filter = log_level.map_or_else( - || match std::env::var("RUST_LOG") { - Ok(env) => EnvFilter::new(env), - #[cfg(debug_assertions)] - _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::DEBUG)), - #[cfg(not(debug_assertions))] - _ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)), + || { + std::env::var("RUST_LOG").map_or_else( + |_| { + if cfg!(debug_assertions) { + EnvFilter::default().add_directive(Directive::from(LevelFilter::DEBUG)) + } else { + EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)) + } + }, + EnvFilter::new, + ) }, |log_level| EnvFilter::default().add_directive(Directive::from(log_level)), ); diff --git a/packages/graph/hash_graph/lib/graph/src/store/pool.rs b/packages/graph/hash_graph/lib/graph/src/store/pool.rs index 32ec1ce56f5..79447c9180e 100644 --- a/packages/graph/hash_graph/lib/graph/src/store/pool.rs +++ b/packages/graph/hash_graph/lib/graph/src/store/pool.rs @@ -10,9 +10,7 @@ pub trait StorePool: Sync { type Error; /// The store returned when acquiring. - type Store<'pool>: Store + Send - where - Self: 'pool; + type Store<'pool>: Store + Send; /// Retrieves a [`Store`] from the pool. async fn acquire(&self) -> Result, Self::Error>; diff --git a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs index 0983cb7ce30..47b40ac8f63 100644 --- a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs +++ b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs @@ -21,7 +21,9 @@ pub struct EntityRecord { pub type RecordStream = impl Stream>; -fn row_stream_to_record_stream(row_stream: RowStream) -> RecordStream { +fn row_stream_to_record_stream( + row_stream: RowStream, +) -> impl Stream> { row_stream.map(|row_result| { let row = row_result.into_report().change_context(QueryError)?; diff --git a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/links.rs b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/links.rs index 8cd726090af..41613e25bef 100644 --- a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/links.rs +++ b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/links.rs @@ -18,7 +18,9 @@ pub struct LinkRecord { pub type RecordStream = impl Stream>; -fn row_stream_to_record_stream(row_stream: RowStream) -> RecordStream { +fn row_stream_to_record_stream( + row_stream: RowStream, +) -> impl Stream> { row_stream.map(|row_result| { let row = row_result.into_report().change_context(QueryError)?; diff --git a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/ontology.rs b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/ontology.rs index bf76b86c1aa..0879e9418bc 100644 --- a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/ontology.rs +++ b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/ontology.rs @@ -27,7 +27,9 @@ pub struct OntologyRecord { pub is_latest: bool, } -fn row_stream_to_record_stream(row_stream: RowStream) -> RecordStream +fn row_stream_to_record_stream( + row_stream: RowStream, +) -> impl Stream, QueryError>> where T: TryFrom, { diff --git a/packages/graph/hash_graph/rust-toolchain.toml b/packages/graph/hash_graph/rust-toolchain.toml index 139cbc5537d..1b246a35024 100644 --- a/packages/graph/hash_graph/rust-toolchain.toml +++ b/packages/graph/hash_graph/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] -channel = "nightly-2022-08-08" +channel = "nightly-2022-09-15" +components = ['rust-src', 'clippy', 'rustfmt'] From dab0fe0368b02283a5c0f76599f26a1b59808c4f Mon Sep 17 00:00:00 2001 From: Tim Diekmann Date: Thu, 15 Sep 2022 14:50:39 +0200 Subject: [PATCH 2/2] Fix formatting --- .../lib/graph/src/store/postgres/context/entity.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs index bc38bac0387..774f47449b3 100644 --- a/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs +++ b/packages/graph/hash_graph/lib/graph/src/store/postgres/context/entity.rs @@ -42,7 +42,7 @@ fn row_stream_to_record_stream( } pub async fn read_all_entities(client: &impl AsClient) -> Result { - let row_stream= client + let row_stream = client .as_client() .query_raw( r#" @@ -55,7 +55,8 @@ pub async fn read_all_entities(client: &impl AsClient) -> Result