aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jake Swenson <jake@jakeswenson.com> 2022-11-19 14:00:53 -0800
committerGravatar Jake Swenson <jake@jakeswenson.com> 2022-11-19 14:00:53 -0800
commit1e4f1d49919bf4dd0cfe1af1fcd95d1d90e4b7ff (patch)
treee9f8b9fe28fca2858ce1c1a54871c022b8374199
parent52b5cb70ec6aaa058d306c9916bcb851f2311730 (diff)
downloadnotion-1e4f1d49919bf4dd0cfe1af1fcd95d1d90e4b7ff.tar.gz
notion-1e4f1d49919bf4dd0cfe1af1fcd95d1d90e4b7ff.tar.zst
notion-1e4f1d49919bf4dd0cfe1af1fcd95d1d90e4b7ff.zip
style(cargo fmt): Add rustfmt config, and fmt code
-rw-r--r--rustfmt.toml17
-rw-r--r--src/ids.rs5
-rw-r--r--src/lib.rs10
-rw-r--r--src/models/error.rs10
-rw-r--r--src/models/paging.rs5
-rw-r--r--src/models/properties/tests.rs2
-rw-r--r--src/models/search.rs5
-rw-r--r--src/models/tests.rs56
8 files changed, 78 insertions, 32 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..5494467
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,17 @@
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=
+edition = "2021"
+
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#fn_args_layout
+fn_args_layout = "Vertical"
+
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#imports_granularity
+# imports_granularity = "Crate" or "Module"?
+
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#required_version
+# required_version = "1.5.1"
+
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#tab_spaces
+tab_spaces = 4
+
+# https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#tab_spaces
+use_field_init_shorthand = true
diff --git a/src/ids.rs b/src/ids.rs
index beffd06..05dac7e 100644
--- a/src/ids.rs
+++ b/src/ids.rs
@@ -41,7 +41,10 @@ macro_rules! identifer {
}
impl std::fmt::Display for $name {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(
+ &self,
+ f: &mut std::fmt::Formatter<'_>,
+ ) -> std::fmt::Result {
self.0.fmt(f)
}
}
diff --git a/src/lib.rs b/src/lib.rs
index bc4b0e7..2b9711b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -72,7 +72,10 @@ impl NotionApi {
Ok(Self { client })
}
- async fn make_json_request(&self, request: RequestBuilder) -> Result<Object, Error> {
+ async fn make_json_request(
+ &self,
+ request: RequestBuilder,
+ ) -> Result<Object, Error> {
let request = request.build()?;
let url = request.url();
tracing::trace!(
@@ -158,7 +161,10 @@ impl NotionApi {
}
/// Get a page by [PageId].
- pub async fn get_page<T: AsIdentifier<PageId>>(&self, page_id: T) -> Result<Page, Error> {
+ pub async fn get_page<T: AsIdentifier<PageId>>(
+ &self,
+ page_id: T,
+ ) -> Result<Page, Error> {
let result = self
.make_json_request(self.client.get(format!(
"https://api.notion.com/v1/pages/{}",
diff --git a/src/models/error.rs b/src/models/error.rs
index e382719..db5ff3f 100644
--- a/src/models/error.rs
+++ b/src/models/error.rs
@@ -12,7 +12,10 @@ impl StatusCode {
}
impl Display for StatusCode {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ fn fmt(
+ &self,
+ f: &mut Formatter<'_>,
+ ) -> std::fmt::Result {
self.0.fmt(f)
}
}
@@ -46,7 +49,10 @@ pub enum ErrorCode {
}
impl Display for ErrorCode {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ fn fmt(
+ &self,
+ f: &mut Formatter<'_>,
+ ) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
diff --git a/src/models/paging.rs b/src/models/paging.rs
index 0f42f23..c38ae11 100644
--- a/src/models/paging.rs
+++ b/src/models/paging.rs
@@ -13,5 +13,8 @@ pub struct Paging {
}
pub trait Pageable {
- fn start_from(self, starting_point: Option<PagingCursor>) -> Self;
+ fn start_from(
+ self,
+ starting_point: Option<PagingCursor>,
+ ) -> Self;
}
diff --git a/src/models/properties/tests.rs b/src/models/properties/tests.rs
index 022f080..86bead8 100644
--- a/src/models/properties/tests.rs
+++ b/src/models/properties/tests.rs
@@ -3,7 +3,7 @@ use chrono::NaiveDate;
#[test]
fn verify_date_parsing() {
- let date = NaiveDate::from_ymd(2021, 01, 02);
+ let date = NaiveDate::from_ymd_opt(2021, 01, 02).unwrap();
let result = serde_json::to_string(&DateOrDateTime::Date(date)).unwrap();
let parsed: DateOrDateTime = serde_json::from_str(&result).unwrap();
println!("{:?}", parsed);
diff --git a/src/models/search.rs b/src/models/search.rs
index e7d8189..ab7567f 100644
--- a/src/models/search.rs
+++ b/src/models/search.rs
@@ -301,7 +301,10 @@ pub struct DatabaseQuery {
}
impl Pageable for DatabaseQuery {
- fn start_from(self, starting_point: Option<PagingCursor>) -> Self {
+ fn start_from(
+ self,
+ starting_point: Option<PagingCursor>,
+ ) -> Self {
DatabaseQuery {
paging: Some(Paging {
start_cursor: starting_point,
diff --git a/src/models/tests.rs b/src/models/tests.rs
index 67e952d..1f41991 100644
--- a/src/models/tests.rs
+++ b/src/models/tests.rs
@@ -62,30 +62,38 @@ fn rich_text() {
fn rich_text_mention_user_person() {
let rich_text_mention_user_person: RichText =
serde_json::from_str(include_str!("tests/rich_text_mention_user_person.json")).unwrap();
- assert_eq!(rich_text_mention_user_person, RichText::Mention {
- rich_text: RichTextCommon {
- plain_text: "@John Doe".to_string(),
- href: None,
- annotations: Some(Annotations {
- bold: Some(false),
- code: Some(false),
- color: Some(TextColor::Default),
- italic: Some(false),
- strikethrough: Some(false),
- underline: Some(false),
- }),
- },
- mention: MentionObject::User {
- user: User::Person {
- common: UserCommon {
- id: UserId::from_str("1118608e-35e8-4fa3-aef7-a4ced85ce8e0").unwrap(),
- name: Some("John Doe".to_string()),
- avatar_url: Some("https://secure.notion-static.com/e6a352a8-8381-44d0-a1dc-9ed80e62b53d.jpg".to_string()),
- },
- person: Person { email: "john.doe@gmail.com".to_string() },
- }
- },
- })
+ assert_eq!(
+ rich_text_mention_user_person,
+ RichText::Mention {
+ rich_text: RichTextCommon {
+ plain_text: "@John Doe".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ mention: MentionObject::User {
+ user: User::Person {
+ common: UserCommon {
+ id: UserId::from_str("1118608e-35e8-4fa3-aef7-a4ced85ce8e0").unwrap(),
+ name: Some("John Doe".to_string()),
+ avatar_url: Some(
+ "https://secure.notion-static.com/e6a352a8-8381-44d0-a1dc-9ed80e62b53d.jpg"
+ .to_string()
+ ),
+ },
+ person: Person {
+ email: "john.doe@gmail.com".to_string()
+ },
+ }
+ },
+ }
+ )
}
#[test]