INNER CODE UNIT · Rust
rand_alphanumeric
ekzhang/sshx · crates/sshx-core/src/lib.rs:22
pub fn rand_alphanumeric(len: usize) -> String {
use rand::{distributions::Alphanumeric, thread_rng, Rng};
thread_rng()
.sample_iter(Alphanumeric)
.take(len)
.map(char::from)
.collect()
}
/// Unique identifier for a shell within the session.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Sid(pub u32);
impl Display for Sid {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}