Skip to content

🐄 Convert Backend's &str to Cow instead #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jasper-Bekkers
Copy link
Contributor

Fixes #44

This is a breaking change to the Backend trait, but it stems from the realization that the i18n macro expansion always would call Cow::from on the result of both available_locales as well as translate.

This PR just moves that responsibility over to the Backend trait directly, this unlocks exactly the "reloadable" backend that the original issue was talking about.

Before

pub trait Backend: Send + Sync + 'static {
    /// Return the available locales
    fn available_locales(&self) -> Vec<&str>;
    /// Get the translation for the given locale and key
    fn translate(&self, locale: &str, key: &str) -> Option<&str>;
}

After

pub trait Backend: Send + Sync + 'static {
    /// Return the available locales
    fn available_locales(&self) -> Vec<Cow<'_, str>>;
    /// Get the translation for the given locale and key
    fn translate(&self, locale: &str, key: &str) -> Option<Cow<'_, str>>;
}

@Jasper-Bekkers Jasper-Bekkers force-pushed the str-to-cow branch 2 times, most recently from 5ac51a8 to 28940aa Compare June 1, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Readme clashes with Backend trait contract
1 participant