-
Notifications
You must be signed in to change notification settings - Fork 264
Add BoundLocaleDataProvider and some impls for it #7621
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
sffc
wants to merge
9
commits into
unicode-org:main
Choose a base branch
from
sffc:boundlocale
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
796e711
Add ZeroTrie cursor into_suffix_trie
sffc fa709cb
Add BoundLocaleDataProvider trait and required types
sffc 0d73021
Add serde converter
sffc 0651106
Implement BoundLocaleDataProvider for icu_provider_blob
sffc df2d3ac
Add HelloWorldAttributeFormatter and fix things for it
sffc 6332af9
Add an optional lifetime to BoundLocaleDataProvider
sffc 131cc93
Simply the BlobBoundLocaleDataProvider docs
sffc c350640
Minor docs fixes
sffc 53d624e
CI cleanup
sffc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ use crate::buf::BufferFormat; | |
| use crate::buf::BufferProvider; | ||
| use crate::data_provider::DynamicDryDataProvider; | ||
| use crate::prelude::*; | ||
| use crate::unstable::BoundLocaleDataProvider; | ||
| use crate::DryDataProvider; | ||
| use serde::de::Deserialize; | ||
| use yoke::Yokeable; | ||
|
|
@@ -59,6 +60,22 @@ where | |
| } | ||
| } | ||
|
|
||
| impl<'a, P> DeserializingBufferProvider<'a, P> { | ||
| /// Wraps the given provider in a [`DeserializingBufferProvider`]. | ||
| /// | ||
| /// This requires enabling the deserialization Cargo feature | ||
| /// for the expected format(s): | ||
| /// | ||
| /// - `deserialize_json` | ||
| /// - `deserialize_postcard_1` | ||
| /// - `deserialize_bincode_1` | ||
| /// | ||
| /// ✨ *Enabled with the `serde` Cargo feature.* | ||
| pub fn new(inner: &'a P) -> Self { | ||
|
||
| Self(inner) | ||
| } | ||
| } | ||
|
|
||
| fn deserialize_impl<'data, M>( | ||
| // Allow `bytes` to be unused in case all buffer formats are disabled | ||
| #[allow(unused_variables)] bytes: &'data [u8], | ||
|
|
@@ -230,6 +247,32 @@ where | |
| } | ||
| } | ||
|
|
||
| impl<P, M> BoundLocaleDataProvider<M> for DeserializingBufferProvider<'_, P> | ||
| where | ||
| M: DynamicDataMarker, | ||
| P: BoundLocaleDataProvider<BufferMarker> + ?Sized, | ||
| for<'de> <M::DataStruct as Yokeable<'de>>::Output: Deserialize<'de>, | ||
| { | ||
| fn load_bound( | ||
| &self, | ||
| req: crate::request::DataAttributesRequest, | ||
| ) -> Result<DataResponse<M>, DataError> { | ||
| let buffer_response = self.0.load_bound(req)?; | ||
| let buffer_format = buffer_response.metadata.buffer_format.ok_or_else(|| { | ||
| DataErrorKind::Deserialize | ||
| .with_str_context("BufferProvider didn't set BufferFormat") | ||
| .with_debug_context(&req) | ||
| })?; | ||
| Ok(DataResponse { | ||
| metadata: buffer_response.metadata, | ||
| payload: buffer_response | ||
| .payload | ||
| .into_deserialized(buffer_format) | ||
| .map_err(|e| e.with_debug_context(&req))?, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "deserialize_json")] | ||
| impl From<serde_json::error::Error> for DataError { | ||
| fn from(e: serde_json::error::Error) -> Self { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you start depending on unstable APIs, do we need to use a ~ dep?