pub fn sequence_a(from: &str, n: u16) -> StringExpand description
Returns a consecutive letter. from is the first letter.
§Example
- If
fromis “z” andnis 1, this function returns “z”. - If
fromis “z” andnis 2, this function returns “aa”. - If
fromis “z” andnis 20, this function returns “ba”.
§Usage
use chrono::{NaiveDate, NaiveDateTime};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Post {
id: u16,
title: String,
approved: bool,
created_at: NaiveDateTime,
}
beaver::define! {
PostFactory (Post) {
id -> |n| n,
// First post's title: "post-a"
// Second post's title: "post-b"
title -> |n| format!("post-{}", beaver::sequence_a("a", n)),
approved -> |_| false,
created_at -> |_| NaiveDate::from_ymd(2020, 1, 1).and_hms(0, 0, 0),
}
}