-
-
Notifications
You must be signed in to change notification settings - Fork 480
Closed
Description
Background
Some people wonder how to use Alphanumeric to generate a string (see #935). While we give an example in the documentation, it might be more obvious to provide a method for this, especially because the efficient implementation requires unsafe code.
Applications are the generation of unique IDs and nonces for APIs such as OAuth.
Feature request
Provide a method of Alphanumeric for generating strings.
Open questions:
- Should we provide
gen_stringsupporting onlyCryptoRngs andgen_string_insecuresupporting any RNG? - Should we
- always generate a new string (
fn gen_string(&self, &mut Rng, usize) -> String), - modify an existing slice (
fn gen_string(&self, &mut Rng, &mut str)) or - push to an existing string (
fn gen_string(&self, &mut Rng, &mut String, usize))?
- always generate a new string (
i. is probably most efficient, because we can call String::from_utf8_unchecked, but it cannot reuse an existing buffer.
ii. is more flexible in that regard, but it requires an initialized buffer.
iii. is the most flexible, but offers little over converting to char and collecting.
Metadata
Metadata
Assignees
Labels
No labels