Skip to content

Commit

Permalink
Update to syn 2 and clap 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-vri-es committed Sep 19, 2023
1 parent cf59ae6 commit 73bf34d
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 48 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ unix-seqpacket = ["tokio-seqpacket"]
unix-stream = ["tokio/net"]

[dependencies]
byteorder = "1.3.4"
filedesc = { version = "0.6.0" }
tokio = { version = "1.0.0", features = ["rt", "sync"] }
byteorder = "1.4.3"
filedesc = { version = "0.6.1" }
tokio = { version = "1.32.0", features = ["rt", "sync"] }
tokio-seqpacket = { version = "0.7.0", optional = true }
fizyr-rpc-macros = { version = "=0.6.0", path = "macros", optional = true }

[dev-dependencies]
assert2 = "0.3.3"
clap = { version = "3.1.10", features = ["derive"] }
tokio = { version = "1.0.0", features = ["macros"] }
assert2 = "0.3.11"
clap = { version = "4.4.4", features = ["derive"] }
tokio = { version = "1.32.0", features = ["macros"] }
fizyr-rpc = { path = ".", features = ["unix-seqpacket", "unix-stream", "tcp"] }
memfile = "0.2.0"
memfile = "0.2.1"

[package.metadata.docs.rs]
features = ["macros", "tcp", "unix-stream", "unix-seqpacket"]
Expand Down
1 change: 0 additions & 1 deletion examples/tcp-client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use fizyr_rpc::TcpPeer;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
#[clap(default_value = "localhost:12345")]
address: String,
Expand Down
1 change: 0 additions & 1 deletion examples/tcp-server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use fizyr_rpc::TcpListener;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
#[clap(default_value = "[::]:12345")]
bind: String,
Expand Down
1 change: 0 additions & 1 deletion examples/unix-seqpacket-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use fizyr_rpc::UnixSeqpacketPeer;
use std::path::PathBuf;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
socket: PathBuf,
}
Expand Down
1 change: 0 additions & 1 deletion examples/unix-seqpacket-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use fizyr_rpc::UnixSeqpacketListener;
use std::path::PathBuf;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
socket: PathBuf,
}
Expand Down
1 change: 0 additions & 1 deletion examples/unix-stream-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use fizyr_rpc::UnixStreamPeer;
use std::path::PathBuf;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
socket: PathBuf,
}
Expand Down
1 change: 0 additions & 1 deletion examples/unix-stream-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use fizyr_rpc::UnixStreamListener;
use std::path::PathBuf;

#[derive(clap::Parser)]
#[clap(setting = clap::AppSettings::DeriveDisplayOrder)]
struct Options {
socket: PathBuf,
}
Expand Down
8 changes: 4 additions & 4 deletions macros-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ publish = []

[dependencies]
fizyr-rpc = { path = "..", features = ["macros"]}
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"

[dev-dependencies]
assert2 = "0.3.5"
assert2 = "0.3.11"
fizyr-rpc = { path = "..", features = ["unix-stream"] }
tokio = { version = "1.0.0", features = ["macros", "net", "rt"] }
tokio = { version = "1.32.0", features = ["macros", "net", "rt"] }
6 changes: 3 additions & 3 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ edition = "2021"
proc_macro = true

[dependencies]
syn = { version = "1.0.72", default-features = false, features = ["derive", "parsing", "printing", "proc-macro"] }
proc-macro2 = "1.0.26"
quote = "1.0.9"
syn = { version = "2.0.37", default-features = false, features = ["derive", "parsing", "printing", "proc-macro"] }
proc-macro2 = "1.0.67"
quote = "1.0.33"
6 changes: 3 additions & 3 deletions macros/src/interface/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ pub mod cooked {
let mut doc = Vec::new();

for attr in attrs {
if attr.path.is_ident("doc") {
match parse_doc_attr_contents(attr.tokens) {
if attr.path().is_ident("doc") {
match parse_doc_attr_contents(attr) {
Ok(x) => doc.push(x),
Err(e) => errors.push(e),
}
} else {
errors.push(syn::Error::new_spanned(attr.path, "unknown attribute"));
errors.push(syn::Error::new_spanned(attr.path(), "unknown attribute"));
}
}

Expand Down
32 changes: 7 additions & 25 deletions macros/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,13 @@ pub fn parse_repeated<T: Parse>(input: ParseStream) -> syn::Result<Vec<T>> {
Ok(result)
}

/// Helper struct to parse `= T` from a token stream.
struct EqAttrContents<T> {
_eq_token: syn::token::Eq,
value: T,
}

impl<T: Parse> Parse for EqAttrContents<T> {
fn parse(input: ParseStream) -> syn::Result<Self> {
Ok(Self {
_eq_token: input.parse()?,
value: input.parse()?,
})
}
}

/// Parse the input tokens as `= T`.
///
/// This is useful for parsing `#[attr = value]` style attributes.
pub fn parse_eq_attr_contents<T: Parse>(input: TokenStream) -> syn::Result<T> {
let parsed: EqAttrContents<T> = syn::parse2(input)?;
Ok(parsed.value)
}

/// Parse the string value of a doc attribute.
pub fn parse_doc_attr_contents(input: TokenStream) -> syn::Result<WithSpan<String>> {
let doc: syn::LitStr = parse_eq_attr_contents(input)?;
pub fn parse_doc_attr_contents(attribute: syn::Attribute) -> syn::Result<WithSpan<String>> {
let meta = attribute.meta.require_name_value()?;
let doc = match &meta.value {
syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(value), .. }) => value,
_ => return Err(syn::Error::new_spanned(&meta.value, "expected a string literal")),
};

Ok(WithSpan::new(doc.span(), doc.value()))
}

0 comments on commit 73bf34d

Please sign in to comment.