-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
In the Rust SDK, regions are just a special newtype for a You can see a list of valid regions here. You could hardcode that list into your app and check that user input matches one of them. Alternatively, you could check that user input conforms to the general shape of a Region: const PREFIX: &[&str] = &[
"us",
"af",
// etc..
];
const MIDDLE: &[&str] = &[
"east",
"west",
// etc...
];
fn validate_region(maybe_region: &str) -> bool {
let mut parts = maybe_region.split("-");
let prefix_is_valid = match parts.next().as_ref() {
Some(prefix) => PREFIX.contains(prefix),
None => false,
};
let middle_is_valid = match parts.next().as_ref() {
Some(middle) => MIDDLE.contains(middle),
None => false,
};
let number_is_valid = match parts.next().as_ref() {
// Region numbers currently range from 1 to 3
Some(number) => number.parse::<u8>().map(|n| n > 0 && n < 4).unwrap_or_default(),
None => false,
};
let only_has_3_parts = parts.next().is_none();
prefix_is_valid && middle_is_valid && number_is_valid && only_has_3_parts
}
fn main() {
for region in [
"us-east-1",
"us-east-1-and-then-some",
"xx-nowhere-99",
"definitely not a region",
"",
].into_iter() {
let valid = if validate_region(region) { "a valid region" } else { "not a valid region" };
println!("region \"{}\" is {}", region, valid);
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
In the Rust SDK, regions are just a special newtype for a
Cow<'static, str>
. We don't validate them in the client. Instead, we rely on the server to validate them.You can see a list of valid regions here. You could hardcode that list into your app and check that user input matches one of them.
Alternatively, you could check that user input conforms to the general shape of a Region: