Skip to content

Commit 7b51ea8

Browse files
est31wezm
authored andcommitted
Replace rental with ouroboros
rental is not maintained any more and users are encouraged to switch to alternatives.
1 parent 02a1fa8 commit 7b51ea8

File tree

4 files changed

+54
-56
lines changed

4 files changed

+54
-56
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ lazy_static = "1.3.0"
2929
libc = "0.2"
3030
log = "0.4"
3131
num-traits = "0.2"
32-
rental = "0.5.5"
32+
ouroboros = "0.9"
3333
rustc-hash = "1.1.0"
3434
tinyvec = { version = "1", features = ["alloc"] }
3535
ucd-trie = "0.1.2"

src/font.rs

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,39 @@ pub enum Images {
9191
Svg(tables::Svg),
9292
}
9393

94-
rental! {
95-
mod tables {
96-
use super::*;
97-
98-
#[rental]
99-
pub struct CBLC {
100-
data: Box<[u8]>,
101-
table: CBLCTable<'data>
102-
}
94+
mod tables {
95+
use ouroboros::self_referencing;
96+
use super::*;
97+
#[self_referencing(pub_extras)]
98+
pub struct CBLC {
99+
data: Box<[u8]>,
100+
#[borrows(data)]
101+
#[not_covariant]
102+
pub(crate) table: CBLCTable<'this>,
103+
}
103104

104-
#[rental(covariant)]
105-
pub struct CBDT {
106-
data: Box<[u8]>,
107-
table: CBDTTable<'data>
108-
}
105+
#[self_referencing(pub_extras)]
106+
pub struct CBDT {
107+
data: Box<[u8]>,
108+
#[borrows(data)]
109+
#[covariant]
110+
pub(crate) table: CBDTTable<'this>,
111+
}
109112

110-
#[rental]
111-
pub struct Sbix {
112-
data: Box<[u8]>,
113-
table: SbixTable<'data>
114-
}
113+
#[self_referencing(pub_extras)]
114+
pub struct Sbix {
115+
data: Box<[u8]>,
116+
#[borrows(data)]
117+
#[not_covariant]
118+
pub(crate) table: SbixTable<'this>,
119+
}
115120

116-
#[rental]
117-
pub struct Svg {
118-
data: Box<[u8]>,
119-
table: SvgTable<'data>
120-
}
121+
#[self_referencing(pub_extras)]
122+
pub struct Svg {
123+
data: Box<[u8]>,
124+
#[borrows(data)]
125+
#[not_covariant]
126+
pub(crate) table: SvgTable<'this>,
121127
}
122128
}
123129

@@ -529,15 +535,15 @@ impl<T: FontTableProvider> Font<T> {
529535
None => return Ok(None),
530536
};
531537
match embedded_bitmaps.as_ref() {
532-
Images::Embedded { cblc, cbdt } => cblc.rent(|cblc: &CBLCTable<'_>| {
538+
Images::Embedded { cblc, cbdt } => cblc.with_table(|cblc: &CBLCTable<'_>| {
533539
let target_ppem = if target_ppem > u16::from(std::u8::MAX) {
534540
std::u8::MAX
535541
} else {
536542
target_ppem as u8
537543
};
538544
let bitmap = match cblc.find_strike(glyph_index, target_ppem, max_bit_depth) {
539545
Some(matching_strike) => {
540-
let cbdt = cbdt.suffix();
546+
let cbdt = cbdt.borrow_table();
541547
cbdt::lookup(glyph_index, &matching_strike, cbdt)?.map(|bitmap| {
542548
BitmapGlyph::try_from((&matching_strike.bitmap_size.inner, bitmap))
543549
})
@@ -565,7 +571,7 @@ impl<T: FontTableProvider> Font<T> {
565571
target_ppem: u16,
566572
max_bit_depth: BitDepth,
567573
) -> Result<Option<BitmapGlyph>, ParseError> {
568-
sbix.rent(|sbix_table: &SbixTable<'_>| {
574+
sbix.with_table(|sbix_table: &SbixTable<'_>| {
569575
match sbix_table.find_strike(glyph_index, target_ppem, max_bit_depth) {
570576
Some(strike) => {
571577
match strike.read_glyph(glyph_index)? {
@@ -604,7 +610,7 @@ impl<T: FontTableProvider> Font<T> {
604610
svg: &tables::Svg,
605611
glyph_index: u16,
606612
) -> Result<Option<BitmapGlyph>, ParseError> {
607-
svg.rent(
613+
svg.with_table(
608614
|svg_table: &SvgTable<'_>| match svg_table.lookup_glyph(glyph_index)? {
609615
Some(svg_record) => BitmapGlyph::try_from(&svg_record).map(Some),
610616
None => Ok(None),
@@ -813,10 +819,10 @@ fn load_cblc_cbdt(
813819
let cblc_data = read_and_box_table(provider, tag::CBLC)?;
814820
let cbdt_data = read_and_box_table(provider, tag::CBDT)?;
815821

816-
let cblc = tables::CBLC::try_new_or_drop(cblc_data, |data| {
822+
let cblc = tables::CBLC::try_new(cblc_data, |data| {
817823
ReadScope::new(data).read::<CBLCTable<'_>>()
818824
})?;
819-
let cbdt = tables::CBDT::try_new_or_drop(cbdt_data, |data| {
825+
let cbdt = tables::CBDT::try_new(cbdt_data, |data| {
820826
ReadScope::new(data).read::<CBDTTable<'_>>()
821827
})?;
822828

@@ -828,14 +834,14 @@ fn load_sbix(
828834
num_glyphs: usize,
829835
) -> Result<tables::Sbix, ParseError> {
830836
let sbix_data = read_and_box_table(provider, tag::SBIX)?;
831-
tables::Sbix::try_new_or_drop(sbix_data, |data| {
837+
tables::Sbix::try_new(sbix_data, |data| {
832838
ReadScope::new(data).read_dep::<SbixTable<'_>>(num_glyphs)
833839
})
834840
}
835841

836842
fn load_svg(provider: &impl FontTableProvider) -> Result<tables::Svg, ParseError> {
837843
let svg_data = read_and_box_table(provider, tag::SVG)?;
838-
tables::Svg::try_new_or_drop(svg_data, |data| ReadScope::new(data).read::<SvgTable<'_>>())
844+
tables::Svg::try_new(svg_data, |data| ReadScope::new(data).read::<SvgTable<'_>>())
839845
}
840846

841847
fn charmap_info(cmap_buf: &[u8]) -> Result<Option<(Encoding, u32)>, ParseError> {

src/glyph_info.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use std::borrow::Cow;
66
use std::collections::HashMap;
77

8+
use ouroboros::self_referencing;
9+
810
use crate::binary::read::ReadScope;
911
use crate::error::ParseError;
1012
use crate::font::Encoding;
@@ -39,21 +41,17 @@ pub fn advance(
3941
}
4042
}
4143

42-
rental! {
43-
mod rentable {
44-
use super::*;
45-
46-
#[rental]
47-
pub struct Post {
48-
data: Box<[u8]>,
49-
table: PostTable<'data>,
50-
}
51-
}
44+
#[self_referencing]
45+
struct Post {
46+
data: Box<[u8]>,
47+
#[borrows(data)]
48+
#[not_covariant]
49+
table: PostTable<'this>,
5250
}
5351

5452
/// Structure for looking up glyph names.
5553
pub struct GlyphNames {
56-
post: Option<rentable::Post>,
54+
post: Option<Post>,
5755
cmap: Option<CmapMappings>,
5856
}
5957

@@ -69,10 +67,10 @@ impl GlyphNames {
6967
post_data: Option<Box<[u8]>>,
7068
) -> Self {
7169
let post = post_data.and_then(|data| {
72-
rentable::Post::try_new_or_drop(data, |data| {
73-
ReadScope::new(data).read::<PostTable<'_>>()
74-
})
75-
.ok()
70+
PostTryBuilder {
71+
data,
72+
table_builder: |data| {ReadScope::new(data).read::<PostTable<'_>>()},
73+
}.try_build().ok()
7674
});
7775
let cmap = cmap_subtable
7876
.as_ref()
@@ -103,9 +101,9 @@ impl GlyphNames {
103101
}
104102
}
105103

106-
impl rentable::Post {
104+
impl Post {
107105
fn glyph_name<'a>(&self, gid: u16) -> Option<Cow<'a, str>> {
108-
self.rent(|post: &PostTable<'_>| {
106+
self.with_table(|post: &PostTable<'_>| {
109107
match post.glyph_name(gid) {
110108
Ok(Some(glyph_name)) if glyph_name != ".notdef" => {
111109
// Doesn't seem possible to avoid this allocation

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ pub mod unicode;
151151
pub mod woff;
152152
pub mod woff2;
153153

154-
// Note from rental docs:
155-
// NOTE for Rust 2018: Relying on implicit crate imports may cause compile errors in code generated
156-
// by this macro. To avoid this, import the crate manually like so
157-
#[macro_use]
158-
extern crate rental;
159-
160154
pub use font::Font;
161155
#[cfg(feature = "outline")]
162156
pub use pathfinder_geometry;

0 commit comments

Comments
 (0)