Skip to content

Commit

Permalink
Fix dead_code warning
Browse files Browse the repository at this point in the history
```
error: function `allow_null` is never used
   --> src/metadata.rs:112:4
    |
112 | fn allow_null<T>(value: Value, f: impl FnOnce(Value) -> Option<T>) -> Option<Option<T>> {
    |    ^^^^^^^^^^
    |
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(dead_code)]`

error: function `into_object` is never used
   --> src/metadata.rs:134:4
    |
134 | fn into_object(value: Value) -> Option<Object> {
    |    ^^^^^^^^^^^

error: methods `remove_object` and `remove_nullable` are never used
   --> src/metadata.rs:145:8
    |
142 | trait ObjectExt {
    |       --------- methods in this trait
...
145 |     fn remove_object(&mut self, key: &'static str) -> ParseResult<Object>;
    |        ^^^^^^^^^^^^^
146 |     fn remove_nullable<T>(
    |        ^^^^^^^^^^^^^^^
```
  • Loading branch information
taiki-e committed Feb 8, 2024
1 parent ab40dc7 commit 06cfd39
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ impl Target {
}
}

#[allow(clippy::option_option)]
fn allow_null<T>(value: Value, f: impl FnOnce(Value) -> Option<T>) -> Option<Option<T>> {
if value.is_null() {
Some(None)
} else {
f(value).map(Some)
}
}
// #[allow(clippy::option_option)]
// fn allow_null<T>(value: Value, f: impl FnOnce(Value) -> Option<T>) -> Option<Option<T>> {
// if value.is_null() {
// Some(None)
// } else {
// f(value).map(Some)
// }
// }

fn into_string<S: From<String>>(value: Value) -> Option<S> {
if let Value::String(string) = value {
Expand All @@ -131,23 +131,23 @@ fn into_array(value: Value) -> Option<Vec<Value>> {
None
}
}
fn into_object(value: Value) -> Option<Object> {
if let Value::Object(object) = value {
Some(object)
} else {
None
}
}
// fn into_object(value: Value) -> Option<Object> {
// if let Value::Object(object) = value {
// Some(object)
// } else {
// None
// }
// }

trait ObjectExt {
fn remove_string<S: From<String>>(&mut self, key: &'static str) -> ParseResult<S>;
fn remove_array(&mut self, key: &'static str) -> ParseResult<Vec<Value>>;
fn remove_object(&mut self, key: &'static str) -> ParseResult<Object>;
fn remove_nullable<T>(
&mut self,
key: &'static str,
f: impl FnOnce(Value) -> Option<T>,
) -> ParseResult<Option<T>>;
// fn remove_object(&mut self, key: &'static str) -> ParseResult<Object>;
// fn remove_nullable<T>(
// &mut self,
// key: &'static str,
// f: impl FnOnce(Value) -> Option<T>,
// ) -> ParseResult<Option<T>>;
}

impl ObjectExt for Object {
Expand All @@ -157,14 +157,14 @@ impl ObjectExt for Object {
fn remove_array(&mut self, key: &'static str) -> ParseResult<Vec<Value>> {
self.remove(key).and_then(into_array).ok_or(key)
}
fn remove_object(&mut self, key: &'static str) -> ParseResult<Object> {
self.remove(key).and_then(into_object).ok_or(key)
}
fn remove_nullable<T>(
&mut self,
key: &'static str,
f: impl FnOnce(Value) -> Option<T>,
) -> ParseResult<Option<T>> {
self.remove(key).and_then(|v| allow_null(v, f)).ok_or(key)
}
// fn remove_object(&mut self, key: &'static str) -> ParseResult<Object> {
// self.remove(key).and_then(into_object).ok_or(key)
// }
// fn remove_nullable<T>(
// &mut self,
// key: &'static str,
// f: impl FnOnce(Value) -> Option<T>,
// ) -> ParseResult<Option<T>> {
// self.remove(key).and_then(|v| allow_null(v, f)).ok_or(key)
// }
}

0 comments on commit 06cfd39

Please sign in to comment.