-
Notifications
You must be signed in to change notification settings - Fork 183
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
Make FFI DataProvider only support BufferProvider #5895
Changes from all commits
75f2fbb
0b6d55e
6def15a
286fa96
c180b41
b935442
f56076c
2487c03
977f201
efc6fe5
696c447
a3e8072
f8bc3fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ pub mod ffi { | |
use alloc::sync::Arc; | ||
use core::fmt::Write; | ||
|
||
#[cfg(any(feature = "compiled_data", feature = "buffer_provider"))] | ||
use crate::errors::ffi::DataError; | ||
use crate::locale_core::ffi::Locale; | ||
#[cfg(feature = "buffer_provider")] | ||
use crate::provider::ffi::DataProvider; | ||
|
||
/// The various calendar types currently supported by [`Calendar`] | ||
|
@@ -126,34 +128,33 @@ pub mod ffi { | |
#[diplomat::rust_link(icu::calendar::AnyCalendar::try_new, FnInEnum)] | ||
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_locale_with_provider")] | ||
#[diplomat::demo(default_constructor)] | ||
#[cfg(feature = "buffer_provider")] | ||
pub fn create_for_locale_with_provider( | ||
provider: &DataProvider, | ||
locale: &Locale, | ||
) -> Result<Box<Calendar>, DataError> { | ||
let prefs = (&locale.0).into(); | ||
|
||
Ok(Box::new(Calendar(Arc::new(call_constructor!( | ||
icu_calendar::AnyCalendar::try_new, | ||
icu_calendar::AnyCalendar::try_new_with_any_provider, | ||
icu_calendar::AnyCalendar::try_new_with_buffer_provider, | ||
provider, | ||
prefs | ||
Ok(Box::new(Calendar(Arc::new(provider.call_constructor( | ||
|provider| icu_calendar::AnyCalendar::try_new_with_buffer_provider(provider, prefs), | ||
)?)))) | ||
} | ||
|
||
/// Creates a new [`Calendar`] from the specified date and time, using a particular data source. | ||
#[diplomat::rust_link(icu::calendar::AnyCalendar::new_for_kind, FnInEnum)] | ||
#[diplomat::attr(supports = fallible_constructors, named_constructor = "for_kind_with_provider")] | ||
#[cfg(feature = "buffer_provider")] | ||
pub fn create_for_kind_with_provider( | ||
provider: &DataProvider, | ||
kind: AnyCalendarKind, | ||
) -> Result<Box<Calendar>, DataError> { | ||
Ok(Box::new(Calendar(Arc::new(call_constructor!( | ||
icu_calendar::AnyCalendar::new_for_kind [r => Ok(r)], | ||
icu_calendar::AnyCalendar::try_new_for_kind_with_any_provider, | ||
icu_calendar::AnyCalendar::try_new_for_kind_with_buffer_provider, | ||
provider, | ||
kind.into() | ||
Ok(Box::new(Calendar(Arc::new(provider.call_constructor( | ||
|provider| { | ||
icu_calendar::AnyCalendar::try_new_for_kind_with_buffer_provider( | ||
provider, | ||
kind.into(), | ||
) | ||
}, | ||
)?)))) | ||
Comment on lines
+151
to
158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't specifically recall a discussion on changing the macro to a closure. It seems like it would be harder in the future to change the behavior back to supporting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this wasn't discussed before: this PR was the discussion opportunity, and I can remove the last N commits if we don't want this. But it should be easy enough to bring back when we need it. I tend to consider macro use to be suboptimal, so if they can be removed without sacrificing anything I try to remove them. Here the complexity has not increased and the main downside is wanting to refactor again in the medium term. |
||
} | ||
|
||
|
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.
I'm okay with this, but @robertbastian pushed back on adding the
From
impls for the fine-grained error types in this crate.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.
hm. we kind of need it to use the closure but we could also not use the closure and revive the macro instead for these few call sites.
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.
hm. we kind of need it to use the closure but we could also not use the closure and revive the macro instead for these few call sites.