Skip to content

Commit 9a3dbe5

Browse files
committed
fluent-fallback 0.2.0
1 parent f85c6f2 commit 9a3dbe5

File tree

9 files changed

+208
-4
lines changed

9 files changed

+208
-4
lines changed

fluent-fallback/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
-
66

7+
## fluent-fallback 0.2.0 (January 12, 2021)
8+
- Separate `Sync` and `Async` bundle generators.
9+
- Reorganize fallback logic.
10+
- Separate out prefetching trait.
11+
- Vendor in pin-cell.
12+
713
## fluent-fallback 0.1.0 (January 3, 2021)
814
- Update `fluent-bundle` to 0.14.
915
- Switch from `elsa` to `chunky-vec`.

fluent-fallback/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = """
44
High-level abstraction model for managing localization resources
55
and runtime localization lifecycle.
66
"""
7-
version = "0.1.0"
7+
version = "0.2.0"
88
edition = "2018"
99
authors = [
1010
"Zibi Braniecki <[email protected]>",
@@ -21,7 +21,6 @@ categories = ["localization", "internationalization"]
2121
chunky-vec = "0.1"
2222
fluent-bundle = { version = "0.14", path = "../fluent-bundle" }
2323
futures = "0.3"
24-
pin-cell = { git = "https://github.com/withoutboats/pin-cell", rev = "4d5803d83c6b3bffd62c9e73a0ceaf5ec6f01495" }
2524
once_cell = "1.5"
2625
async-trait = "0.1"
2726

fluent-fallback/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use crate::generator::{BundleIterator, BundleStream};
1010
use chunky_vec::ChunkyVec;
1111
use futures::{ready, Stream};
12-
use pin_cell::{PinCell, PinMut};
12+
use crate::pin_cell::{PinCell, PinMut};
1313

1414
pub struct Cache<I, R>
1515
where

fluent-fallback/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ mod errors;
33
pub mod generator;
44
mod localization;
55
pub mod types;
6+
mod pin_cell;
67

78
pub use localization::Localization;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a temporary fork of https://github.com/withoutboats/pin-cell until
2+
https://github.com/withoutboats/pin-cell/issues/6 gets resolved.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#![deny(missing_docs, missing_debug_implementations)]
2+
//! This library defines the `PinCell` type, a pinning variant of the standard
3+
//! library's `RefCell`.
4+
//!
5+
//! It is not safe to "pin project" through a `RefCell` - getting a pinned
6+
//! reference to something inside the `RefCell` when you have a pinned
7+
//! refernece to the `RefCell` - because `RefCell` is too powerful.
8+
//!
9+
//! A `PinCell` is slightly less powerful than `RefCell`: unlike a `RefCell`,
10+
//! one cannot get a mutable reference into a `PinCell`, only a pinned mutable
11+
//! reference (`Pin<&mut T>`). This makes pin projection safe, allowing you
12+
//! to use interior mutability with the knowledge that `T` will never actually
13+
//! be moved out of the `RefCell` that wraps it.
14+
15+
mod pin_ref;
16+
mod pin_mut;
17+
18+
use core::cell::{RefCell, RefMut, BorrowMutError};
19+
use core::pin::Pin;
20+
21+
pub use pin_ref::PinRef;
22+
pub use pin_mut::PinMut;
23+
24+
/// A mutable memory location with dynamically checked borrow rules
25+
///
26+
/// Unlike `RefCell`, this type only allows *pinned* mutable access to the
27+
/// inner value, enabling a "pin-safe" version of interior mutability.
28+
///
29+
/// See the standard library documentation for more information.
30+
#[derive(Default, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
31+
pub struct PinCell<T: ?Sized> {
32+
inner: RefCell<T>,
33+
}
34+
35+
impl<T> PinCell<T> {
36+
/// Creates a new `PinCell` containing `value`.
37+
pub const fn new(value: T) -> PinCell<T> {
38+
PinCell { inner: RefCell::new(value) }
39+
}
40+
}
41+
42+
impl<T: ?Sized> PinCell<T> {
43+
/// Mutably borrows the wrapped value, preserving its pinnedness.
44+
///
45+
/// The borrow lasts until the returned `PinMut` or all `PinMut`s derived
46+
/// from it exit scope. The value cannot be borrowed while this borrow is
47+
/// active.
48+
pub fn borrow_mut<'a>(self: Pin<&'a Self>) -> PinMut<'a, T> {
49+
self.try_borrow_mut().expect("already borrowed")
50+
}
51+
52+
/// Mutably borrows the wrapped value, preserving its pinnedness,
53+
/// returning an error if the value is currently borrowed.
54+
///
55+
/// The borrow lasts until the returned `PinMut` or all `PinMut`s derived
56+
/// from it exit scope. The value cannot be borrowed while this borrow is
57+
/// active.
58+
///
59+
/// This is the non-panicking variant of `borrow_mut`.
60+
pub fn try_borrow_mut<'a>(self: Pin<&'a Self>) -> Result<PinMut<'a, T>, BorrowMutError> {
61+
let ref_mut: RefMut<'a, T> = Pin::get_ref(self).inner.try_borrow_mut()?;
62+
63+
// this is a pin projection from Pin<&PinCell<T>> to Pin<RefMut<T>>
64+
// projecting is safe because:
65+
//
66+
// - for<T: ?Sized> (PinCell<T>: Unpin) imples (RefMut<T>: Unpin)
67+
// holds true
68+
// - PinCell does not implement Drop
69+
//
70+
// see discussion on tracking issue #49150 about pin projection
71+
// invariants
72+
let pin_ref_mut: Pin<RefMut<'a, T>> = unsafe {
73+
Pin::new_unchecked(ref_mut)
74+
};
75+
76+
Ok(PinMut { inner: pin_ref_mut })
77+
}
78+
}
79+
80+
impl<T> From<T> for PinCell<T> {
81+
fn from(value: T) -> PinCell<T> {
82+
PinCell::new(value)
83+
}
84+
}
85+
86+
impl<T> From<RefCell<T>> for PinCell<T> {
87+
fn from(cell: RefCell<T>) -> PinCell<T> {
88+
PinCell { inner: cell }
89+
}
90+
}
91+
92+
impl<T> Into<RefCell<T>> for PinCell<T> {
93+
fn into(self) -> RefCell<T> {
94+
self.inner
95+
}
96+
}
97+
98+
// TODO CoerceUnsized
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use core::cell::RefMut;
2+
use core::fmt;
3+
use core::ops::Deref;
4+
use core::pin::Pin;
5+
6+
#[derive(Debug)]
7+
/// A wrapper type for a mutably borrowed value from a `PinCell<T>`.
8+
pub struct PinMut<'a, T: ?Sized> {
9+
pub(crate) inner: Pin<RefMut<'a, T>>,
10+
}
11+
12+
impl<'a, T: ?Sized> Deref for PinMut<'a, T> {
13+
type Target = T;
14+
15+
fn deref(&self) -> &T {
16+
&*self.inner
17+
}
18+
}
19+
20+
21+
impl<'a, T: ?Sized> PinMut<'a, T> {
22+
/// Get a pinned mutable reference to the value inside this wrapper.
23+
pub fn as_mut<'b>(orig: &'b mut PinMut<'a, T>) -> Pin<&'b mut T> {
24+
orig.inner.as_mut()
25+
}
26+
}
27+
28+
/* TODO implement these APIs
29+
30+
impl<'a, T: ?Sized> PinMut<'a, T> {
31+
pub fn map<U, F>(orig: PinMut<'a, T>, f: F) -> PinMut<'a, U> where
32+
F: FnOnce(Pin<&mut T>) -> Pin<&mut U>,
33+
{
34+
panic!()
35+
}
36+
37+
pub fn map_split<U, V, F>(orig: PinMut<'a, T>, f: F) -> (PinMut<'a, U>, PinMut<'a, V>) where
38+
F: FnOnce(Pin<&mut T>) -> (Pin<&mut U>, Pin<&mut V>)
39+
{
40+
panic!()
41+
}
42+
}
43+
*/
44+
45+
impl<'a, T: fmt::Display + ?Sized> fmt::Display for PinMut<'a, T> {
46+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47+
<T as fmt::Display>::fmt(&**self, f)
48+
}
49+
}
50+
51+
// TODO CoerceUnsized
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use core::cell::Ref;
2+
use core::fmt;
3+
use core::ops::Deref;
4+
use core::pin::Pin;
5+
6+
#[derive(Debug)]
7+
/// A wrapper type for a immutably borrowed value from a `PinCell<T>`.
8+
pub struct PinRef<'a, T: ?Sized> {
9+
pub(crate) inner: Pin<Ref<'a, T>>,
10+
}
11+
12+
impl<'a, T: ?Sized> Deref for PinRef<'a, T> {
13+
type Target = T;
14+
15+
fn deref(&self) -> &T {
16+
&*self.inner
17+
}
18+
}
19+
20+
/* TODO implement these APIs
21+
22+
impl<'a, T: ?Sized> PinRef<'a, T> {
23+
pub fn clone(orig: &PinRef<'a, T>) -> PinRef<'a, T> {
24+
panic!()
25+
}
26+
27+
pub fn map<U, F>(orig: PinRef<'a, T>, f: F) -> PinRef<'a, U> where
28+
F: FnOnce(Pin<&T>) -> Pin<&U>,
29+
{
30+
panic!()
31+
}
32+
33+
pub fn map_split<U, V, F>(orig: PinRef<'a, T>, f: F) -> (PinRef<'a, U>, PinRef<'a, V>) where
34+
F: FnOnce(Pin<&T>) -> (Pin<&U>, Pin<&V>)
35+
{
36+
panic!()
37+
}
38+
}
39+
*/
40+
41+
impl<'a, T: fmt::Display + ?Sized> fmt::Display for PinRef<'a, T> {
42+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43+
<T as fmt::Display>::fmt(&**self, f)
44+
}
45+
}
46+
47+
// TODO CoerceUnsized

fluent-resmgr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ categories = ["localization", "internationalization"]
1919
[dependencies]
2020
fluent-bundle = { version = "0.14", path = "../fluent-bundle" }
2121
unic-langid = "0.9"
22-
fluent-fallback = { version = "0.1.0", path = "../fluent-fallback" }
22+
fluent-fallback = { version = "0.2.0", path = "../fluent-fallback" }
2323
elsa = "1.3.2"
2424
futures = "0.3"
2525

0 commit comments

Comments
 (0)