Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reverse the polarity of conversions, fix clippy #1335

Merged
merged 6 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl FieldSet {
{
ValueSet {
fields: self,
values: &values.borrow()[..],
values: values.borrow(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ impl From<Option<Level>> for LevelFilter {
}
}

impl Into<Option<Level>> for LevelFilter {
impl From<LevelFilter> for Option<Level> {
#[inline]
fn into(self) -> Option<Level> {
self.into_level()
fn from(filter: LevelFilter) -> Self {
filter.into_level()
}
}

Expand Down
33 changes: 18 additions & 15 deletions tracing-core/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ impl Id {
}
}

impl<'a> Into<Option<Id>> for &'a Id {
fn into(self) -> Option<Id> {
Some(self.clone())
impl<'a> From<&'a Id> for Option<Id> {
fn from(id: &'a Id) -> Self {
Some(id.clone())
}
}

Expand Down Expand Up @@ -292,26 +292,29 @@ impl Current {
}
}

impl<'a> Into<Option<&'a Id>> for &'a Current {
fn into(self) -> Option<&'a Id> {
self.id()
impl<'a> From<&'a Current> for Option<&'a Id> {
fn from(cur: &'a Current) -> Self {
cur.id()
}
}

impl<'a> Into<Option<Id>> for &'a Current {
fn into(self) -> Option<Id> {
self.id().cloned()
impl<'a> From<&'a Current> for Option<Id> {
fn from(cur: &'a Current) -> Self {
cur.id().cloned()
}
}

impl Into<Option<Id>> for Current {
fn into(self) -> Option<Id> {
self.id().cloned()
impl From<Current> for Option<Id> {
fn from(cur: Current) -> Self {
match cur.inner {
CurrentInner::Current { id, .. } => Some(id),
_ => None,
}
}
}

impl<'a> Into<Option<&'static Metadata<'static>>> for &'a Current {
fn into(self) -> Option<&'static Metadata<'static>> {
self.metadata()
impl<'a> From<&'a Current> for Option<&'static Metadata<'static>> {
fn from(cur: &'a Current) -> Self {
cur.metadata()
}
}
6 changes: 3 additions & 3 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ where
}
}

impl<N, E, F, W> Into<tracing_core::Dispatch> for CollectorBuilder<N, E, F, W>
impl<N, E, F, W> From<CollectorBuilder<N, E, F, W>> for tracing_core::Dispatch
where
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<Registry, N> + 'static,
Expand All @@ -599,8 +599,8 @@ where
fmt_subscriber::Subscriber<Registry, N, E, W>:
subscribe::Subscribe<Registry> + Send + Sync + 'static,
{
fn into(self) -> tracing_core::Dispatch {
tracing_core::Dispatch::new(self.finish())
fn from(builder: CollectorBuilder<N, E, F, W>) -> tracing_core::Dispatch {
tracing_core::Dispatch::new(builder.finish())
}
}

Expand Down
12 changes: 6 additions & 6 deletions tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,15 +1297,15 @@ impl fmt::Debug for Span {
}
}

impl<'a> Into<Option<&'a Id>> for &'a Span {
fn into(self) -> Option<&'a Id> {
self.inner.as_ref().map(|inner| &inner.id)
impl<'a> From<&'a Span> for Option<&'a Id> {
fn from(span: &'a Span) -> Self {
span.inner.as_ref().map(|inner| &inner.id)
}
}

impl<'a> Into<Option<Id>> for &'a Span {
fn into(self) -> Option<Id> {
self.inner.as_ref().map(Inner::id)
impl<'a> From<&'a Span> for Option<Id> {
fn from(span: &'a Span) -> Self {
span.inner.as_ref().map(Inner::id)
}
}

Expand Down
6 changes: 3 additions & 3 deletions tracing/tests/support/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ impl MockField {
}
}

impl Into<Expect> for MockField {
fn into(self) -> Expect {
impl From<MockField> for Expect {
fn from(field: MockField) -> Self {
Expect {
fields: HashMap::new(),
only: false,
}
.and(self)
.and(field)
}
}

Expand Down
8 changes: 4 additions & 4 deletions tracing/tests/support/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ impl fmt::Display for MockSpan {
}
}

impl Into<NewSpan> for MockSpan {
fn into(self) -> NewSpan {
NewSpan {
span: self,
impl From<MockSpan> for NewSpan {
fn from(span: MockSpan) -> Self {
Self {
span,
..Default::default()
}
}
Expand Down