Move skip_fmt into tor-basic-utils

Code motion and the minimal mechanical changes.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/375#note_2783078
This commit is contained in:
Ian Jackson 2022-03-04 11:42:49 +00:00
parent aba68088d1
commit ebfd734956
18 changed files with 59 additions and 54 deletions

13
Cargo.lock generated
View File

@ -138,7 +138,7 @@ dependencies = [
"thiserror",
"tokio",
"tokio-util",
"tor-bytes",
"tor-basic-utils",
"tor-chanmgr",
"tor-circmgr",
"tor-config",
@ -3084,7 +3084,6 @@ dependencies = [
"arrayref",
"bytes",
"digest 0.10.3",
"educe",
"generic-array",
"getrandom 0.2.5",
"hex-literal",
@ -3107,6 +3106,7 @@ dependencies = [
"hex-literal",
"rand 0.8.5",
"thiserror",
"tor-basic-utils",
"tor-bytes",
"tor-cert",
"tor-error",
@ -3142,7 +3142,7 @@ dependencies = [
"postage",
"rand 0.8.5",
"thiserror",
"tor-bytes",
"tor-basic-utils",
"tor-error",
"tor-linkspec",
"tor-llcrypto",
@ -3179,7 +3179,7 @@ dependencies = [
"serde",
"static_assertions",
"thiserror",
"tor-bytes",
"tor-basic-utils",
"tor-chanmgr",
"tor-config",
"tor-error",
@ -3276,7 +3276,7 @@ dependencies = [
"tempfile",
"thiserror",
"time",
"tor-bytes",
"tor-basic-utils",
"tor-checkable",
"tor-circmgr",
"tor-config",
@ -3327,7 +3327,7 @@ dependencies = [
"retain_mut",
"serde",
"thiserror",
"tor-bytes",
"tor-basic-utils",
"tor-config",
"tor-error",
"tor-linkspec",
@ -3470,6 +3470,7 @@ dependencies = [
"thiserror",
"tokio",
"tokio-util",
"tor-basic-utils",
"tor-bytes",
"tor-cell",
"tor-cert",

View File

@ -28,7 +28,7 @@ error_detail = [ ]
experimental-api = []
[dependencies]
tor-bytes = { path="../tor-bytes", version = "0.1.0"}
tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"}
tor-circmgr = { path="../tor-circmgr", version = "0.1.0"}
tor-config = { path="../tor-config", version = "0.1.0"}
tor-chanmgr = { path="../tor-chanmgr", version = "0.1.0"}

View File

@ -6,7 +6,7 @@ use std::{borrow::Cow, fmt, time::SystemTime};
use derive_more::Display;
use educe::Educe;
use futures::{Stream, StreamExt};
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
use tor_chanmgr::{ConnBlockage, ConnStatus, ConnStatusEvents};
use tor_dirmgr::{DirBootstrapEvents, DirBootstrapStatus};
use tracing::debug;

View File

@ -28,3 +28,40 @@
#![deny(clippy::unnecessary_wraps)]
#![warn(clippy::unseparated_literal_suffix)]
#![deny(clippy::unwrap_used)]
use std::fmt;
// ----------------------------------------------------------------------
/// Function with the signature of `Debug::fmt` that just prints `".."`
///
/// ```
/// use educe::Educe;
/// use tor_basic_utils::skip_fmt;
///
/// #[derive(Educe, Default)]
/// #[educe(Debug)]
/// struct Wombat {
/// visible: usize,
///
/// #[educe(Debug(method = "skip_fmt"))]
/// invisible: [u8; 2],
/// }
///
/// assert_eq!( format!("{:?}", &Wombat::default()),
/// "Wombat { visible: 0, invisible: .. }" );
/// ```
//
// This function is here in tor-bytes because crates that want to use it will largely
// be trying to avoid dumping packet data.
// But, it may at some point want to move to a lower-layer crate.
// If we do that, we should `pub use` it here, if we don't want a semver break.
pub fn skip_fmt<T>(_: &T, f: &mut fmt::Formatter) -> fmt::Result {
/// Inner function avoids code bloat due to generics
fn inner(f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "..")
}
inner(f)
}
// ----------------------------------------------------------------------

View File

@ -23,7 +23,6 @@ thiserror = "1"
[dev-dependencies]
hex-literal = "0.3"
educe = "0.4.6"
[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.2.3", features = ["js"] }

View File

@ -82,8 +82,6 @@ mod impls;
mod reader;
mod writer;
use std::fmt;
pub use err::Error;
pub use reader::Reader;
pub use writer::Writer;
@ -196,39 +194,6 @@ pub trait Readable: Sized {
// ----------------------------------------------------------------------
/// Function with the signature of `Debug::fmt` that just prints `".."`
///
/// ```
/// use educe::Educe;
/// use tor_bytes::skip_fmt;
///
/// #[derive(Educe, Default)]
/// #[educe(Debug)]
/// struct Wombat {
/// visible: usize,
///
/// #[educe(Debug(method = "skip_fmt"))]
/// invisible: [u8; 2],
/// }
///
/// assert_eq!( format!("{:?}", &Wombat::default()),
/// "Wombat { visible: 0, invisible: .. }" );
/// ```
//
// This function is here in tor-bytes because crates that want to use it will largely
// be trying to avoid dumping packet data.
// But, it may at some point want to move to a lower-layer crate.
// If we do that, we should `pub use` it here, if we don't want a semver break.
pub fn skip_fmt<T>(_: &T, f: &mut fmt::Formatter) -> fmt::Result {
/// Inner function avoids code bloat due to generics
fn inner(f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "..")
}
inner(f)
}
// ----------------------------------------------------------------------
#[cfg(test)]
mod test {
use super::*;

View File

@ -13,6 +13,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/"
[dependencies]
caret = { path="../caret", version = "0.1.0"}
educe = "0.4.6"
tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"}
tor-llcrypto = { path="../tor-llcrypto", version = "0.1.0"}
tor-bytes = { path="../tor-bytes", version = "0.1.0"}
tor-cert = { path="../tor-cert", version = "0.1.0"}

View File

@ -3,7 +3,8 @@
use super::{ChanCmd, RawCellBody, CELL_DATA_LEN};
use std::convert::TryInto;
use std::net::{IpAddr, Ipv4Addr};
use tor_bytes::{self, skip_fmt, Error, Readable, Reader, Result, Writer};
use tor_basic_utils::skip_fmt;
use tor_bytes::{self, Error, Readable, Reader, Result, Writer};
use caret::caret_int;
use educe::Educe;

View File

@ -13,7 +13,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/"
[features]
[dependencies]
tor-bytes = { path="../tor-bytes", version = "0.1.0"}
tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"}
tor-error = { path="../tor-error", version = "0.1.0"}
tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"}
tor-proto = { path="../tor-proto", version = "0.1.0"}

View File

@ -8,7 +8,7 @@ use std::{
fmt,
time::{Duration, Instant},
};
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
/// The status of our connection to the internet.
#[derive(Default, Debug, Clone)]

View File

@ -18,7 +18,7 @@ repository="https://gitlab.torproject.org/tpo/core/arti.git/"
experimental-api = []
[dependencies]
tor-bytes = { path = "../tor-bytes", version = "0.1.0"}
tor-basic-utils = { path = "../tor-basic-utils", version = "0.1.0"}
tor-chanmgr = { path="../tor-chanmgr", version = "0.1.0"}
tor-config = { path="../tor-config", version = "0.1.0"}
tor-error = { path="../tor-error", version = "0.1.0"}

View File

@ -9,7 +9,7 @@ use educe::Educe;
use futures::future::OptionFuture;
use std::convert::TryInto;
use std::sync::Arc;
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
use tor_error::internal;
use tor_proto::circuit::{CircParameters, ClientCirc};
use tor_rtcompat::Runtime;

View File

@ -18,8 +18,8 @@ static = ["rusqlite/bundled"]
routerdesc = ["tor-dirclient/routerdesc"]
[dependencies]
tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"}
retry-error = { path = "../retry-error", version = "0.1.0"}
tor-bytes = { path="../tor-bytes", version = "0.1.0"}
tor-checkable = { path = "../tor-checkable", version = "0.1.0"}
tor-circmgr = { path = "../tor-circmgr", version = "0.1.0"}
tor-config = { path = "../tor-config", version = "0.1.0"}

View File

@ -19,7 +19,7 @@ use std::{
use educe::Educe;
use futures::{stream::Stream, Future, StreamExt};
use time::OffsetDateTime;
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
use tor_netdoc::doc::netstatus;
/// An event that a DirMgr can broadcast to indicate that a change in

View File

@ -18,7 +18,7 @@ default = []
testing = []
[dependencies]
tor-bytes = { path="../tor-bytes", version = "0.1.0"}
tor-basic-utils = { path="../tor-basic-utils", version = "0.1.0"}
tor-config = { path="../tor-config", version = "0.1.0"}
tor-error = { path="../tor-error", version = "0.1.0"}
tor-netdir = { path="../tor-netdir", version = "0.1.0"}

View File

@ -21,7 +21,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::task::{Context, Poll};
use std::time::Instant;
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
/// A future used to see if we have "permission" to use a guard.
///

View File

@ -17,6 +17,7 @@ ntor_v3 = []
tokio = ["tokio-crate", "tokio-util"]
[dependencies]
tor-basic-utils = { path = "../tor-basic-utils", version = "0.1.0"}
tor-llcrypto = { path = "../tor-llcrypto", version = "0.1.0"}
tor-bytes = { path = "../tor-bytes", version = "0.1.0"}
tor-cert = { path = "../tor-cert", version = "0.1.0"}

View File

@ -23,7 +23,7 @@ use educe::Educe;
use crate::circuit::StreamTarget;
use crate::stream::StreamReader;
use tor_bytes::skip_fmt;
use tor_basic_utils::skip_fmt;
use tor_cell::relaycell::msg::{Data, RelayMsg};
use tor_error::internal;