mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 02:39:32 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
3e0e51c108
commit
bc45c7659a
321 changed files with 11210 additions and 9720 deletions
|
@ -2,9 +2,11 @@
|
|||
name = "stdx"
|
||||
version = "0.0.0"
|
||||
description = "TBD"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.65"
|
||||
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
|
||||
|
||||
use std::io as sio;
|
||||
use std::process::Command;
|
||||
use std::{cmp::Ordering, ops, time::Instant};
|
||||
use std::{io as sio, iter};
|
||||
|
||||
mod macros;
|
||||
pub mod hash;
|
||||
|
@ -39,15 +39,19 @@ Uncomment `default = [ "backtrace" ]` in `crates/stdx/Cargo.toml`.
|
|||
}
|
||||
|
||||
pub fn to_lower_snake_case(s: &str) -> String {
|
||||
to_snake_case(s, char::to_ascii_lowercase)
|
||||
to_snake_case(s, char::to_lowercase)
|
||||
}
|
||||
pub fn to_upper_snake_case(s: &str) -> String {
|
||||
to_snake_case(s, char::to_ascii_uppercase)
|
||||
to_snake_case(s, char::to_uppercase)
|
||||
}
|
||||
|
||||
// Code partially taken from rust/compiler/rustc_lint/src/nonstandard_style.rs
|
||||
// commit: 9626f2b
|
||||
fn to_snake_case<F: Fn(&char) -> char>(mut s: &str, change_case: F) -> String {
|
||||
fn to_snake_case<F, I>(mut s: &str, change_case: F) -> String
|
||||
where
|
||||
F: Fn(char) -> I,
|
||||
I: Iterator<Item = char>,
|
||||
{
|
||||
let mut words = vec![];
|
||||
|
||||
// Preserve leading underscores
|
||||
|
@ -75,7 +79,7 @@ fn to_snake_case<F: Fn(&char) -> char>(mut s: &str, change_case: F) -> String {
|
|||
}
|
||||
|
||||
last_upper = ch.is_uppercase();
|
||||
buf.extend(iter::once(change_case(&ch)));
|
||||
buf.extend(change_case(ch));
|
||||
}
|
||||
|
||||
words.push(buf);
|
||||
|
|
|
@ -43,5 +43,14 @@ macro_rules! impl_from {
|
|||
}
|
||||
)*)?
|
||||
)*
|
||||
};
|
||||
($($variant:ident$(<$V:ident>)?),* for $enum:ident) => {
|
||||
$(
|
||||
impl$(<$V>)? From<$variant$(<$V>)?> for $enum$(<$V>)? {
|
||||
fn from(it: $variant$(<$V>)?) -> $enum$(<$V>)? {
|
||||
$enum::$variant(it)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue