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

Update dependency versions. #17

Merged
merged 4 commits into from
Jan 11, 2025
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ license = "MIT OR Apache-2.0"

[dependencies]
nom = { version = "7.1.3", default-features = false, features = ["alloc"] }
serde = { version = "1.0.196", optional = true, features = ["derive"] }
serde = { version = "1.0.217", optional = true, features = ["derive"] }

[dev-dependencies]
pretty_assertions = "1.4.0"
serde_yaml = "0.9.31"
pretty_assertions = "1.4.1"
serde_yaml = "0.9.34"

[features]
default = []
Expand Down
7 changes: 6 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
edition = "2021"
format_code_in_doc_comments = true
merge_imports = true
imports_granularity = "crate"
reorder_impl_items = true
style_edition = "2021"
use_field_init_shorthand = true
wrap_comments = true
47 changes: 29 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![no_std]
// #![deny(missing_docs, missing_debug_implementations)]

//! Returns type names with a specifiable number of module segments as a `String`.
//! Returns type names with a specifiable number of module segments as a
//! `String`.
//!
//! # Usage
//!
Expand Down Expand Up @@ -42,12 +43,12 @@
//!
//! # Motivation
//!
//! The [`core::any::type_name`] function stabilized in Rust 1.38 returns the fully qualified type
//! name with all module segments. This can be difficult to read in error messages, especially for
//! type-parameterized types.
//! The [`core::any::type_name`] function stabilized in Rust 1.38 returns the
//! fully qualified type name with all module segments. This can be difficult to
//! read in error messages, especially for type-parameterized types.
//!
//! Often, the simple type name is more readable, and enough to distinguish the type referenced in
//! an error.
//! Often, the simple type name is more readable, and enough to distinguish the
//! type referenced in an error.
//!
//! [`core::any::type_name`]: https://doc.rust-lang.org/std/any/fn.type_name.html

Expand Down Expand Up @@ -92,7 +93,8 @@ where
///
/// # Parameters
///
/// * `type_params_fmt_opts`: How to format type parameters, see the type documentation for details.
/// * `type_params_fmt_opts`: How to format type parameters, see the type
/// documentation for details.
///
/// # Type Parameters
///
Expand Down Expand Up @@ -126,7 +128,8 @@ where
type_namemn_opts::<T>(0, 0, type_params_fmt_opts)
}

/// Returns the type name with at most `m` most significant module path segments.
/// Returns the type name with at most `m` most significant module path
/// segments.
///
/// # Parameters
///
Expand All @@ -151,12 +154,14 @@ where
type_namemn::<T>(m, 0)
}

/// Returns the type name with at most `m` most significant module path segments.
/// Returns the type name with at most `m` most significant module path
/// segments.
///
/// # Parameters
///
/// * `m`: Number of most significant module path segments to include.
/// * `type_params_fmt_opts`: How to format type parameters, see the type documentation for details.
/// * `type_params_fmt_opts`: How to format type parameters, see the type
/// documentation for details.
///
/// # Type Parameters
///
Expand Down Expand Up @@ -193,7 +198,8 @@ where
type_namemn_opts::<T>(m, 0, type_params_fmt_opts)
}

/// Returns the type name with at most `n` least significant module path segments.
/// Returns the type name with at most `n` least significant module path
/// segments.
///
/// # Parameters
///
Expand All @@ -218,12 +224,14 @@ where
type_namemn::<T>(0, n)
}

/// Returns the type name with at most `n` least significant module path segments.
/// Returns the type name with at most `n` least significant module path
/// segments.
///
/// # Parameters
///
/// * `n`: Number of least significant module path segments to include.
/// * `type_params_fmt_opts`: How to format type parameters, see the type documentation for details.
/// * `type_params_fmt_opts`: How to format type parameters, see the type
/// documentation for details.
///
/// # Type Parameters
///
Expand Down Expand Up @@ -256,7 +264,8 @@ where
type_namemn_opts::<T>(0, n, type_params_fmt_opts)
}

/// Returns the type name with `m` most significant, and `n` least significant module path segments.
/// Returns the type name with `m` most significant, and `n` least significant
/// module path segments.
///
/// # Parameters
///
Expand All @@ -282,13 +291,15 @@ where
type_namemn_opts::<T>(m, n, TypeParamsFmtOpts::All)
}

/// Returns the type name with `m` most significant, and `n` least significant module path segments.
/// Returns the type name with `m` most significant, and `n` least significant
/// module path segments.
///
/// # Parameters
///
/// * `m`: Number of most significant module path segments to include.
/// * `n`: Number of least significant module path segments to include.
/// * `type_params_fmt_opts`: How to format type parameters, see the type documentation for details.
/// * `type_params_fmt_opts`: How to format type parameters, see the type
/// documentation for details.
///
/// # Type Parameters
///
Expand Down Expand Up @@ -461,9 +472,9 @@ mod tests {

#[test]
fn type_name_usize_mn() {
assert_eq!(tynm::type_namem::<usize>(core::usize::MAX), "::usize");
assert_eq!(tynm::type_namem::<usize>(usize::MAX), "::usize");
assert_eq!(
tynm::type_namemn::<usize>(core::usize::MAX, core::usize::MAX),
tynm::type_namemn::<usize>(usize::MAX, usize::MAX),
"::usize"
);
}
Expand Down
24 changes: 13 additions & 11 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ pub fn struct_type(input: &str) -> IResult<&str, TypeNameStruct> {
}

pub fn named_primitive_or_struct(input: &str) -> IResult<&str, TypeName> {
// Check for primitive types first, otherwise we cannot distinguish the `std::u32` module from
// `u32` (type).
// Check for primitive types first, otherwise we cannot distinguish the
// `std::u32` module from `u32` (type).
//
// We shouldn't have to worry about `use crate::u32; u32::SomeType` as the type name input
// should be the fully qualified crate name as determined by Rust.
// We shouldn't have to worry about `use crate::u32; u32::SomeType` as the type
// name input should be the fully qualified crate name as determined by
// Rust.
if let Some(result) = named_primitive(input) {
result
} else {
Expand All @@ -234,12 +235,12 @@ pub fn trait_type(input: &str) -> IResult<&str, TypeName> {

/// Parses a type name.
pub fn type_name(input: &str) -> IResult<&str, TypeName> {
// Primitive types begin with lowercase letters, but we have to detect them at this level, as
// lower parsers (`module_name`, `type_simple_name`) cannot tell if `"std::"` precedes the input
// it is given.
// Primitive types begin with lowercase letters, but we have to detect them at
// this level, as lower parsers (`module_name`, `type_simple_name`) cannot
// tell if `"std::"` precedes the input it is given.
//
// In addition, types may begin with symbols, and we should detect them here and branch to the
// relevant parsing functions.
// In addition, types may begin with symbols, and we should detect them here and
// branch to the relevant parsing functions.
let mut chars = input.chars();
if let Some(first_char) = chars.next() {
match first_char {
Expand All @@ -255,8 +256,9 @@ pub fn type_name(input: &str) -> IResult<&str, TypeName> {
if let Some(remainder) = split.next() {
trait_type(remainder)
} else {
// We only have "dyn" as a token. User may have specified r#dyn as a struct name or function
// name, but this is unusual. For now, we treat it as a struct.
// We only have "dyn" as a token. User may have specified r#dyn as a struct
// name or function name, but this is unusual. For
// now, we treat it as a struct.
Ok((
"",
TypeName::Struct(TypeNameStruct {
Expand Down
3 changes: 2 additions & 1 deletion src/type_name_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use alloc::string::String;
pub struct TypeNameInfo {
/// The short type name, e.g. `"Option<String>"`.
pub short_name: String,
/// The full type name, e.g. `"core::option::Option<alloc::string::String>"`.
/// The full type name, e.g.
/// `"core::option::Option<alloc::string::String>"`.
pub full_name: String,
}

Expand Down
Loading
Loading