Skip to content

Commit

Permalink
Set all crates to 2021 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Aug 20, 2023
1 parent 4708f14 commit b273382
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 128 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["development-tools::debugging"]
keywords = ["logging"]
exclude = ["rfcs/**/*"]
rust-version = "1.60.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["std", "serde", "kv_unstable_std", "kv_unstable_sval", "kv_unstable_serde"]
Expand Down
3 changes: 0 additions & 3 deletions benches/value.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![cfg(feature = "kv_unstable")]
#![feature(test)]

extern crate log;
extern crate test;

use log::kv::Value;

#[bench]
Expand Down
16 changes: 4 additions & 12 deletions src/kv/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ mod std_support {
mod sval_support {
use super::*;

extern crate sval;
extern crate sval_ref;

use self::sval::Value;
use self::sval_ref::ValueRef;
use sval::Value;
use sval_ref::ValueRef;

impl<'a> Value for Key<'a> {
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(
Expand All @@ -119,10 +116,7 @@ mod sval_support {
}

impl<'a> ValueRef<'a> for Key<'a> {
fn stream_ref<S: self::sval::Stream<'a> + ?Sized>(
&self,
stream: &mut S,
) -> self::sval::Result {
fn stream_ref<S: sval::Stream<'a> + ?Sized>(&self, stream: &mut S) -> sval::Result {
self.key.stream(stream)
}
}
Expand All @@ -132,9 +126,7 @@ mod sval_support {
mod serde_support {
use super::*;

extern crate serde;

use self::serde::{Serialize, Serializer};
use serde::{Serialize, Serializer};

impl<'a> Serialize for Key<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
72 changes: 29 additions & 43 deletions src/kv/source.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
//! Sources for key-value pairs.

#[cfg(feature = "kv_unstable_sval")]
extern crate sval;
#[cfg(feature = "kv_unstable_sval")]
extern crate sval_ref;

#[cfg(feature = "kv_unstable_serde")]
extern crate serde;

use kv::{Error, Key, ToKey, ToValue, Value};
use crate::kv::{Error, Key, ToKey, ToValue, Value};
use std::fmt;

/// A source of key-value pairs.
Expand Down Expand Up @@ -64,7 +56,7 @@ pub trait Source {
fn count(&self) -> usize;
}

/// The default implemention of `Source::get`
/// The default implementation of `Source::get`
pub(crate) fn get_default<'v>(source: &'v (impl Source + ?Sized), key: Key) -> Option<Value<'v>> {
struct Get<'k, 'v> {
key: Key<'k>,
Expand Down Expand Up @@ -319,7 +311,7 @@ mod std_support {
Ok(())
}

fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
fn get(&self, key: Key) -> Option<Value<'_>> {
BTreeMap::get(self, key.as_str()).map(|v| v.to_value())
}

Expand All @@ -330,10 +322,12 @@ mod std_support {

#[cfg(test)]
mod tests {
use super::*;
use kv::value::tests::Token;
use std::collections::{BTreeMap, HashMap};

use crate::kv::value::tests::Token;

use super::*;

#[test]
fn count() {
assert_eq!(1, Source::count(&Box::new(("a", 1))));
Expand Down Expand Up @@ -462,17 +456,17 @@ where
mod sval_support {
use super::*;

impl<S> self::sval::Value for AsMap<S>
impl<S> sval::Value for AsMap<S>
where
S: Source,
{
fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>(
fn stream<'sval, SV: sval::Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut SV,
) -> self::sval::Result {
) -> sval::Result {
struct StreamVisitor<'a, V: ?Sized>(&'a mut V);

impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
impl<'a, 'kvs, V: sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
self.0
.map_key_begin()
Expand All @@ -498,31 +492,31 @@ mod sval_support {

stream
.map_begin(Some(self.count()))
.map_err(|_| self::sval::Error::new())?;
.map_err(|_| sval::Error::new())?;

self.visit(&mut StreamVisitor(stream))
.map_err(|_| self::sval::Error::new())?;
.map_err(|_| sval::Error::new())?;

stream.map_end().map_err(|_| self::sval::Error::new())
stream.map_end().map_err(|_| sval::Error::new())
}
}

impl<S> self::sval::Value for AsList<S>
impl<S> sval::Value for AsList<S>
where
S: Source,
{
fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>(
fn stream<'sval, SV: sval::Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut SV,
) -> self::sval::Result {
) -> sval::Result {
struct StreamVisitor<'a, V: ?Sized>(&'a mut V);

impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
impl<'a, 'kvs, V: sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
self.0
.seq_value_begin()
.map_err(|_| Error::msg("failed to stream seq value"))?;
self::sval_ref::stream_ref(self.0, (key, value))
sval_ref::stream_ref(self.0, (key, value))
.map_err(|_| Error::msg("failed to stream seq value"))?;
self.0
.seq_value_end()
Expand All @@ -534,24 +528,20 @@ mod sval_support {

stream
.seq_begin(Some(self.count()))
.map_err(|_| self::sval::Error::new())?;
.map_err(|_| sval::Error::new())?;

self.visit(&mut StreamVisitor(stream))
.map_err(|_| self::sval::Error::new())?;
.map_err(|_| sval::Error::new())?;

stream.seq_end().map_err(|_| self::sval::Error::new())
stream.seq_end().map_err(|_| sval::Error::new())
}
}

#[cfg(test)]
mod tests {
extern crate sval_derive;

use super::*;

use self::sval_derive::Value;

use crate::kv::source;
use sval_derive::Value;

#[test]
fn derive_stream() {
Expand All @@ -575,8 +565,7 @@ pub mod as_map {
//! `serde` adapters for serializing a `Source` as a map.

use super::*;

use self::serde::{Serialize, Serializer};
use serde::{Serialize, Serializer};

/// Serialize a `Source` as a map.
pub fn serialize<T, S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -593,8 +582,7 @@ pub mod as_list {
//! `serde` adapters for serializing a `Source` as a list.

use super::*;

use self::serde::{Serialize, Serializer};
use serde::{Serialize, Serializer};

/// Serialize a `Source` as a list.
pub fn serialize<T, S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -609,8 +597,7 @@ pub mod as_list {
#[cfg(feature = "kv_unstable_serde")]
mod serde_support {
use super::*;

use self::serde::ser::{Error as SerError, Serialize, SerializeMap, SerializeSeq, Serializer};
use serde::ser::{Error as SerError, Serialize, SerializeMap, SerializeSeq, Serializer};

impl<T> Serialize for AsMap<T>
where
Expand Down Expand Up @@ -677,10 +664,8 @@ mod serde_support {
#[cfg(test)]
mod tests {
use super::*;

use self::serde::Serialize;

use crate::kv::source;
use serde::Serialize;

#[test]
fn derive_serialize() {
Expand All @@ -705,8 +690,9 @@ mod serde_support {

#[cfg(test)]
mod tests {
use crate::kv::value::tests::Token;

use super::*;
use kv::value::tests::Token;

#[test]
fn source_is_object_safe() {
Expand Down
48 changes: 17 additions & 31 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

use std::fmt;

extern crate value_bag;
pub use crate::kv::Error;

#[cfg(feature = "kv_unstable_sval")]
extern crate sval;
#[cfg(feature = "kv_unstable_sval")]
extern crate sval_ref;

#[cfg(feature = "kv_unstable_serde")]
extern crate serde;

use self::value_bag::ValueBag;

pub use kv::Error;
use value_bag::ValueBag;

/// A type that can be converted into a [`Value`](struct.Value.html).
pub trait ToValue {
Expand Down Expand Up @@ -199,7 +189,7 @@ impl<'v> Value<'v> {
/// Get a value from a type implementing `serde::Serialize`.
pub fn capture_serde<T>(value: &'v T) -> Self
where
T: self::serde::Serialize + 'static,
T: serde::Serialize + 'static,
{
Value {
inner: ValueBag::capture_serde1(value),
Expand All @@ -210,7 +200,7 @@ impl<'v> Value<'v> {
#[cfg(feature = "kv_unstable_sval")]
pub fn capture_sval<T>(value: &'v T) -> Self
where
T: self::sval::Value + 'static,
T: sval::Value + 'static,
{
Value {
inner: ValueBag::capture_sval2(value),
Expand Down Expand Up @@ -241,7 +231,7 @@ impl<'v> Value<'v> {
#[cfg(feature = "kv_unstable_serde")]
pub fn from_serde<T>(value: &'v T) -> Self
where
T: self::serde::Serialize,
T: serde::Serialize,
{
Value {
inner: ValueBag::from_serde1(value),
Expand All @@ -252,7 +242,7 @@ impl<'v> Value<'v> {
#[cfg(feature = "kv_unstable_sval")]
pub fn from_sval<T>(value: &'v T) -> Self
where
T: self::sval::Value,
T: sval::Value,
{
Value {
inner: ValueBag::from_sval2(value),
Expand Down Expand Up @@ -406,29 +396,26 @@ impl ToValue for dyn std::error::Error + 'static {
}

#[cfg(feature = "kv_unstable_serde")]
impl<'v> self::serde::Serialize for Value<'v> {
impl<'v> serde::Serialize for Value<'v> {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
S: self::serde::Serializer,
S: serde::Serializer,
{
self.inner.serialize(s)
}
}

#[cfg(feature = "kv_unstable_sval")]
impl<'v> self::sval::Value for Value<'v> {
fn stream<'sval, S: self::sval::Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut S,
) -> self::sval::Result {
self::sval::Value::stream(&self.inner, stream)
impl<'v> sval::Value for Value<'v> {
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(&'sval self, stream: &mut S) -> sval::Result {
sval::Value::stream(&self.inner, stream)
}
}

#[cfg(feature = "kv_unstable_sval")]
impl<'v> self::sval_ref::ValueRef<'v> for Value<'v> {
fn stream_ref<S: self::sval::Stream<'v> + ?Sized>(&self, stream: &mut S) -> self::sval::Result {
self::sval_ref::ValueRef::stream_ref(&self.inner, stream)
impl<'v> sval_ref::ValueRef<'v> for Value<'v> {
fn stream_ref<S: sval::Stream<'v> + ?Sized>(&self, stream: &mut S) -> sval::Result {
sval_ref::ValueRef::stream_ref(&self.inner, stream)
}
}

Expand Down Expand Up @@ -601,10 +588,10 @@ impl<'v> Value<'v> {

#[cfg(feature = "kv_unstable_std")]
mod std_support {
use super::*;

use std::borrow::Cow;

use super::*;

impl<T> ToValue for Box<T>
where
T: ToValue + ?Sized,
Expand Down Expand Up @@ -773,8 +760,7 @@ where
#[cfg(test)]
pub(crate) mod tests {
use super::*;

pub(crate) use super::value_bag::test::TestToken as Token;
pub(crate) use value_bag::test::TestToken as Token;

impl<'v> Value<'v> {
pub(crate) fn to_token(&self) -> Token {
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,10 @@
#[cfg(all(not(feature = "std"), not(test)))]
extern crate core as std;

use std::cmp;
#[cfg(feature = "std")]
use std::error;
use std::fmt;
use std::mem;
use std::str::FromStr;
use std::{cmp, fmt, mem};

#[macro_use]
mod macros;
Expand Down Expand Up @@ -1537,9 +1535,7 @@ const fn get_max_level_inner() -> LevelFilter {

#[cfg(test)]
mod tests {
extern crate std;
use super::{Level, LevelFilter, ParseLevelError};
use tests::std::string::ToString;

#[test]
fn test_levelfilter_from_str() {
Expand Down Expand Up @@ -1748,7 +1744,7 @@ mod tests {
#[cfg(feature = "kv_unstable")]
fn test_record_key_values_builder() {
use super::Record;
use kv::{self, Visitor};
use crate::kv::{self, Visitor};

struct TestVisitor {
seen_pairs: usize,
Expand Down
Loading

0 comments on commit b273382

Please sign in to comment.