Skip to content

Commit

Permalink
Replace uses of derivative with derive_more or plain derive
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Dec 11, 2024
1 parent 97f4442 commit 45cf384
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 66 deletions.
63 changes: 28 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ bzip2 = "0.4"
byteorder = "1"
cfg-if = "1"
cstr = "0.2.10"
derivative = "2"
digest = "0.10"
either = "1"
getset = "0.1"
Expand Down Expand Up @@ -78,9 +77,9 @@ version = "0.4"
default-features = false

[dependencies.derive_more]
version = "0.99"
version = "1"
default-features = false
features = ["deref", "display", "from", "try_into"]
features = ["deref", "display", "debug", "from", "try_into"]

[dependencies.flate2]
version = "1"
Expand Down
6 changes: 3 additions & 3 deletions src/hg_connect_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use curl_sys::{
CURLOPT_POSTFIELDSIZE_LARGE, CURLOPT_READDATA, CURLOPT_READFUNCTION, CURLOPT_URL,
CURLOPT_USERAGENT, CURLOPT_VERBOSE, CURLOPT_WRITEFUNCTION,
};
use derive_more::Debug;
use either::Either;
use flate2::read::ZlibDecoder;
use itertools::Itertools;
Expand Down Expand Up @@ -258,15 +259,14 @@ struct HttpResponseInfo {
content_type: Option<String>,
}

#[derive(Derivative)]
#[derivative(Debug)]
#[derive(Debug)]
pub struct HttpResponse {
info: HttpResponseInfo,
thread: Option<JoinHandle<Result<(), (c_int, HttpRequest)>>>,
cursor: Cursor<ImmutBString>,
receiver: Option<Receiver<HttpRequestChannelData>>,
#[allow(dead_code)]
#[derivative(Debug = "ignore")]
#[debug(skip)]
token: Arc<GitHttpStateToken>,
}

Expand Down
8 changes: 4 additions & 4 deletions src/hg_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::borrow::Cow;
use std::io::Write;

use bstr::{BStr, ByteSlice};
use derive_more::Debug;
use once_cell::sync::Lazy;
use regex::bytes::Regex;

Expand All @@ -29,12 +30,11 @@ pub struct HgAuthorship<B: AsRef<[u8]>> {
#[derive(Clone)]
pub struct HgCommitter<B: AsRef<[u8]>>(pub B);

#[derive(Derivative)]
#[derivative(Debug)]
#[derive(Debug)]
struct Authorship<'a> {
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
#[debug("{}", name.as_bstr())]
name: Cow<'a, [u8]>,
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
#[debug("{}", email.as_bstr())]
email: Cow<'a, [u8]>,
timestamp: u64,
utcoffset: i32,
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#![deny(clippy::unused_self)]
#![allow(unknown_lints)]

#[macro_use]
extern crate derivative;
#[macro_use]
extern crate log;

Expand Down
6 changes: 3 additions & 3 deletions src/tree_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ use std::io::{self, Write};
use std::iter::{zip, Peekable};

use bstr::{BStr, BString, ByteSlice};
use derive_more::Debug;
use either::Either;
use itertools::EitherOrBoth;

use crate::util::{ImmutBString, Map, MapMap, Transpose};

/// Wrapper type that pairs a value of any type with a path string.
#[derive(Clone, Derivative, PartialEq, Eq, PartialOrd, Ord)]
#[derivative(Debug)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct WithPath<T> {
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
#[debug("{}", path.as_bstr())]
path: ImmutBString,
inner: T,
}
Expand Down
4 changes: 0 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ impl<T: FromStr> FromBytes for T {
}
}

pub fn bstr_fmt<S: AsRef<[u8]>>(s: &S, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(s.as_ref().as_bstr(), f)
}

pub trait OptionExt<T> {
fn as_ptr(&self) -> *const T;
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::git::CommitId;
use crate::{experiment, get_typed_config, ConfigType, Experiments};

#[derive(Clone, Display, Debug)]
#[display(fmt = "{version}")]
#[display("{version}")]
pub struct Version {
version: semver::Version,
tag_has_v_prefix: bool,
Expand Down
19 changes: 8 additions & 11 deletions src/xdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use std::ffi::c_void;
use std::marker::PhantomData;
use std::os::raw::{c_char, c_int, c_long, c_ulong};
use std::ptr::NonNull;

use bstr::ByteSlice;
use derive_more::Debug;

use crate::util::ImmutBString;

Expand All @@ -30,27 +32,23 @@ impl<'a> From<&'a [u8]> for mmfile_t<'a> {

#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Derivative)]
#[derivative(Default)]
#[derive(Default)]
struct xpparam_t {
flags: c_ulong,
#[derivative(Default(value = "std::ptr::null()"))]
anchors: *const *const c_char,
anchors: Option<NonNull<*const c_char>>,
anchors_nr: usize,
}

#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Derivative)]
#[derivative(Default)]
#[derive(Default)]
struct xdemitconf_t {
ctxlen: c_long,
interhunkctxlen: c_long,
flags: c_ulong,
find_func:
Option<extern "C" fn(*const c_char, c_long, *const c_char, c_long, *mut c_void) -> c_long>,
#[derivative(Default(value = "std::ptr::null_mut()"))]
find_func_priv: *mut c_void,
find_func_priv: Option<NonNull<c_void>>,
hunk_func: Option<extern "C" fn(c_long, c_long, c_long, c_long, *mut c_void) -> c_int>,
}

Expand All @@ -68,12 +66,11 @@ extern "C" {
) -> c_int;
}

#[derive(Clone, Copy, Derivative)]
#[derivative(Debug)]
#[derive(Clone, Copy, Debug)]
pub struct PatchInfo<S: AsRef<[u8]>> {
pub start: usize,
pub end: usize,
#[derivative(Debug(format_with = "crate::util::bstr_fmt"))]
#[debug("{}", data.as_ref().as_bstr())]
pub data: S,
}

Expand Down

0 comments on commit 45cf384

Please sign in to comment.