pub struct SimpleLang { /* private fields */ }Expand description
简单多语言实现 — 基础键值对存储
对齐 PHP think\Lang 的最小可用实现,不依赖文件加载、cookie、header
检测等。适用于单元测试和简单场景。
§PHP 对齐
- 键不区分大小写(对齐 PHP
strtolower($name)) - 找不到时返回 name 本身(对齐 PHP
?? $name)
§用法
ⓘ
use sz_rust_core::validate::message::{Lang, SimpleLang};
let lang = SimpleLang::new()
.set("not conform to the rules", "不符合规则")
.set("require", "必须填写");
assert!(lang.has("require"));
assert_eq!(lang.get("require"), "必须填写");
assert_eq!(lang.get("NOT FOUND"), "NOT FOUND"); // 找不到返回原值Implementations§
Source§impl SimpleLang
impl SimpleLang
Sourcepub fn new() -> SimpleLang
pub fn new() -> SimpleLang
创建空的语言包
Sourcepub fn set(self, name: &str, value: &str) -> SimpleLang
pub fn set(self, name: &str, value: &str) -> SimpleLang
添加翻译条目(对齐 PHP $this->lang[$range][strtolower($name)] = $value)
Trait Implementations§
Source§impl Clone for SimpleLang
impl Clone for SimpleLang
Source§fn clone(&self) -> SimpleLang
fn clone(&self) -> SimpleLang
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SimpleLang
impl Debug for SimpleLang
Source§impl Default for SimpleLang
impl Default for SimpleLang
Source§fn default() -> SimpleLang
fn default() -> SimpleLang
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SimpleLang
impl RefUnwindSafe for SimpleLang
impl Send for SimpleLang
impl Sync for SimpleLang
impl Unpin for SimpleLang
impl UnsafeUnpin for SimpleLang
impl UnwindSafe for SimpleLang
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.