Skip to content

Commit

Permalink
[IFT] add comment to WritableOffset about DIVISOR.
Browse files Browse the repository at this point in the history
  • Loading branch information
garretrieger committed Jan 17, 2025
1 parent 44d9c72 commit 6a54cec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions incremental-font-transfer/src/glyph_keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,23 @@ fn retained_glyphs_total_size<T: GlyphDataOffsetArray>(
Ok(total_size)
}

trait WritableOffset<const DIV: usize> {
/// Objects with this trait can be written to bytes.
///
/// The offset value will be divided by DIVISOR prior to conversion to bytes.
trait WritableOffset<const DIVISOR: usize> {
fn write_to(self, dest: &mut [u8]);
}

impl<const DIV: usize> WritableOffset<DIV> for u32 {
impl<const DIVISOR: usize> WritableOffset<DIVISOR> for u32 {
fn write_to(self, dest: &mut [u8]) {
let data: [u8; 4] = (self / DIV as u32).to_raw();
let data: [u8; 4] = (self / DIVISOR as u32).to_raw();
dest[..4].copy_from_slice(&data);
}
}

impl<const DIV: usize> WritableOffset<DIV> for u16 {
impl<const DIVISOR: usize> WritableOffset<DIVISOR> for u16 {
fn write_to(self, dest: &mut [u8]) {
let data: [u8; 2] = (self / DIV as u16).to_raw();
let data: [u8; 2] = (self / DIVISOR as u16).to_raw();
dest[..2].copy_from_slice(&data);
}
}
Expand Down

0 comments on commit 6a54cec

Please sign in to comment.