Debian Codegraph @

debian/rust-vendor/icu_datetime/src/provider/compat.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 use core::any::TypeId;
6
7 use icu_provider::prelude::*;
8 use icu_time::provider::TimezonePeriodsV1;
9
10 /// Data provider for compatibility with old 2.x buffer providers
11 pub(crate) struct CompatProvider<P0, P1>(pub(crate) P0, pub(crate) P1);
12
13 impl<M, P0, P1> DataProvider<M> for CompatProvider<P0, P1>
14 where
15 M: DataMarker,
16 P0: DataProvider<M>,
17 P1: BufferProvider,
18 {
19 fn load(&self, req: DataRequest) -> Result<DataResponse<M>, DataError> {
20 let original_error = match self.0.load(req) {
21 Err(
22 e @ DataError {
23 kind: DataErrorKind::MarkerNotFound,
24 ..
25 },
26 ) => e,
27 other => return other,
28 };
29 if TypeId::of::<M>() == TypeId::of::<TimezonePeriodsV1>() {
30 crate::provider::time_zones::legacy::metazone_timezone_compat(&self.1, req)
31 .and_then(DataResponse::dynamic_cast)
32 } else {
33 Err(original_error)
34 }
35 }
36 }