use std::sync::Arc;
pub use crate::geom;
pub use crate::geom::{DeviceRect, DeviceSize, Matrix, Point, Rect};
pub const IR_SCHEMA_VERSION: u32 = 4;
macro_rules! handle {
($(#[$doc:meta])* $name:ident) => {
$(#[$doc])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct $name(pub u32);
impl $name {
pub fn index(self) -> usize {
self.0 as usize
}
}
};
}
handle!(
PathId
);
handle!(
PaintId
);
handle!(
StrokeStyleId
);
handle!(
GlyphRunId
);
handle!(
ImageId
);
handle!(
MaskId
);
handle!(
TransparencyGroupId
);
handle!(
ShadingId
);
handle!(
TilingId
);
handle!(
FontId
);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ResourceKey {
pub object_number: u32,
pub generation: u16,
pub variant: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FillRule {
NonZero,
EvenOdd,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlendMode {
Normal,
Multiply,
Screen,
Overlay,
Darken,
Lighten,
ColorDodge,
ColorBurn,
HardLight,
SoftLight,
Difference,
Exclusion,
Hue,
Saturation,
Color,
Luminosity,
}
impl BlendMode {
pub fn is_separable(self) -> bool {
!matches!(
self,
BlendMode::Hue | BlendMode::Saturation | BlendMode::Color | BlendMode::Luminosity
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterpolationMode {
Nearest,
Bilinear,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
impl Color {
pub const WHITE: Color = Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
};
pub const BLACK: Color = Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub const fn from_rgb(r: f32, g: f32, b: f32) -> Color {
Color { r, g, b, a: 1.0 }
}
}
#[derive(Debug, Clone)]
pub enum Paint {
Solid(Color),
Pattern {
tiling: TilingId,
matrix: Matrix,
},
Shading {
shading: ShadingId,
matrix: Matrix,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PathVerb {
MoveTo,
LineTo,
CurveTo,
Close,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PathData {
pub verbs: Arc<[PathVerb]>,
pub points: Arc<[Point]>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineCap {
Butt,
Round,
Square,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineJoin {
Miter,
Round,
Bevel,
}
#[derive(Debug, Clone)]
pub struct StrokeStyle {
pub width: f64,
pub cap: LineCap,
pub join: LineJoin,
pub miter_limit: f64,
pub dash_pattern: Arc<[f64]>,
pub dash_phase: f64,
}
#[derive(Debug, Clone, Copy)]
pub struct PlacedGlyph {
pub glyph: u32,
pub x: f64,
pub y: f64,
}
#[derive(Debug, Clone)]
pub struct GlyphRun {
pub font: FontId,
pub font_size: f64,
pub transform: Matrix,
pub glyphs: Arc<[PlacedGlyph]>,
pub render_mode: u8,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GlyphStroke {
pub paint: PaintId,
pub style: StrokeStyleId,
pub alpha: f32,
}
#[derive(Debug, Clone)]
pub struct FontResource {
pub key: ResourceKey,
pub program: Arc<[u8]>,
pub face_index: u32,
pub synthetic_shear: f32,
pub synthetic_embolden_em: f32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IccCmykTransform {
pub grid: u8,
pub input_tables: [Arc<[f32]>; 4],
pub clut: Arc<[[f32; 3]]>,
pub output_tables: [Arc<[f32]>; 3],
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImageColorSpace {
Gray,
Rgb,
Cmyk,
Indexed {
base: Box<ImageColorSpace>,
hival: u32,
lookup: Arc<[u8]>,
},
TintLut {
rgb: Arc<[u8]>,
},
TintLut2 {
rgb: Arc<[u8]>,
},
IccRgb {
trc: Arc<[f32]>,
matrix: [f32; 9],
},
IccCmyk {
transform: Arc<IccCmykTransform>,
},
Lab {
white_point: [f32; 3],
range: [f32; 4],
},
}
impl ImageColorSpace {
pub fn components(&self) -> usize {
match self {
ImageColorSpace::Gray => 1,
ImageColorSpace::Rgb => 3,
ImageColorSpace::Cmyk => 4,
ImageColorSpace::Lab { .. } => 3,
ImageColorSpace::Indexed { .. } => 1,
ImageColorSpace::TintLut { .. } => 1,
ImageColorSpace::TintLut2 { .. } => 2,
ImageColorSpace::IccRgb { .. } => 3,
ImageColorSpace::IccCmyk { .. } => 4,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct SharedBytes(Arc<Vec<u8>>);
impl SharedBytes {
#[inline]
pub fn as_slice(&self) -> &[u8] {
self.0.as_slice()
}
}
impl From<Vec<u8>> for SharedBytes {
fn from(bytes: Vec<u8>) -> Self {
Self(Arc::new(bytes))
}
}
impl From<&[u8]> for SharedBytes {
fn from(bytes: &[u8]) -> Self {
Self::from(bytes.to_vec())
}
}
impl std::ops::Deref for SharedBytes {
type Target = [u8];
fn deref(&self) -> &Self::Target {
self.as_slice()
}
}
impl AsRef<[u8]> for SharedBytes {
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ImageSMask {
pub width: u32,
pub height: u32,
pub bits_per_component: u8,
pub decode: Option<Arc<[[f32; 2]]>>,
pub samples: Arc<[u8]>,
pub codec: Option<ImageCodecKind>,
pub codec_data: Option<SharedBytes>,
pub codec_parms: Option<CodecParms>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImageMask {
ColorKey(Arc<[[u32; 2]]>),
Stencil(Arc<ImageSMask>),
}
#[derive(Debug, Clone)]
pub struct ImageIr {
pub key: ResourceKey,
pub width: u32,
pub height: u32,
pub is_stencil: bool,
pub interpolation: InterpolationMode,
pub soft_mask: Option<MaskId>,
pub bits_per_component: u8,
pub color_space: ImageColorSpace,
pub decode: Option<Arc<[[f32; 2]]>>,
pub samples: Option<Arc<[u8]>>,
pub codec: Option<ImageCodecKind>,
pub codec_data: Option<SharedBytes>,
pub codec_parms: Option<CodecParms>,
pub smask: Option<Arc<ImageSMask>>,
pub mask: Option<ImageMask>,
pub smask_in_data: u8,
pub lowering_degraded: bool,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct CodecParms {
pub jbig2_globals: Option<Arc<[u8]>>,
pub k: i32,
pub columns: u32,
pub rows: u32,
pub black_is_1: bool,
pub byte_align: bool,
pub end_of_line: bool,
pub end_of_block: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageCodecKind {
Dct,
Jpx,
Jbig2,
CcittFax,
}
#[derive(Debug, Clone)]
pub struct MaskResource {
pub key: ResourceKey,
pub kind: MaskKind,
}
pub type TransferLut = Arc<[u8; 256]>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MaskKind {
Alpha,
Luminosity,
LuminosityBc {
backdrop: [u8; 3],
},
}
#[derive(Debug, Clone)]
pub struct TransparencyGroup {
pub isolated: bool,
pub knockout: bool,
pub bounds: Rect,
pub opacity: f32,
pub blend: BlendMode,
}
#[derive(Debug, Clone)]
pub struct ShadingResource {
pub key: ResourceKey,
pub shading_type: u8,
pub kind: ShadingKind,
pub bbox: Option<[f32; 4]>,
}
#[derive(Debug, Clone)]
pub enum ShadingKind {
Axial {
coords: [f32; 4],
domain: [f32; 2],
extend: [bool; 2],
ramp: Arc<[Color]>,
background: Option<Color>,
},
Radial {
coords: [f32; 6],
domain: [f32; 2],
extend: [bool; 2],
ramp: Arc<[Color]>,
background: Option<Color>,
},
Unsupported { background: Option<Color> },
MeshTriangles {
triangles: Arc<[[MeshVertex; 3]]>,
background: Option<Color>,
},
MeshPatches {
patches: Arc<[MeshPatch]>,
background: Option<Color>,
},
FunctionGrid {
domain: [f32; 4],
matrix: Matrix,
grid_w: u32,
grid_h: u32,
colors: Arc<[Color]>,
background: Option<Color>,
},
}
#[derive(Debug, Clone, Copy)]
pub struct MeshVertex {
pub x: f32,
pub y: f32,
pub color: Color,
}
#[derive(Debug, Clone, Copy)]
pub struct MeshPatch {
pub points: [[f32; 2]; 16],
pub colors: [Color; 4],
}
#[derive(Debug, Clone)]
pub struct TilingPattern {
pub key: ResourceKey,
pub uncolored: bool,
pub under_color: Color,
pub bbox: [f32; 4],
pub x_step: f32,
pub y_step: f32,
pub cell: Arc<CompiledPage>,
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PageFeatures: u64 {
const BASIC_PATHS = 1 << 0;
const TEXT = 1 << 1;
const IMAGES = 1 << 2;
const CLIPPING = 1 << 3;
const TRANSPARENCY = 1 << 4;
const SOFT_MASKS = 1 << 5;
const PATTERNS = 1 << 6;
const SHADINGS = 1 << 7;
const TYPE3_FONTS = 1 << 8;
const ICC_COLOR = 1 << 9;
const NONSEPARABLE_BLENDS = 1 << 10;
const OVERPRINT = 1 << 11;
const STENCIL_MASKS = 1 << 12;
const DASHED_STROKES = 1 << 13;
const NEEDS_DCT = 1 << 14;
const NEEDS_JPX = 1 << 15;
const NEEDS_JBIG2 = 1 << 16;
const NEEDS_CCITT = 1 << 17;
}
}
impl PageFeatures {
pub const CODEC_MASK: PageFeatures = PageFeatures::NEEDS_DCT
.union(PageFeatures::NEEDS_JPX)
.union(PageFeatures::NEEDS_JBIG2)
.union(PageFeatures::NEEDS_CCITT);
pub fn required_codecs(self) -> PageFeatures {
self.intersection(Self::CODEC_MASK)
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct PageComplexity {
pub operation_count: u32,
pub path_segment_count: u32,
pub glyph_count: u32,
pub image_pixels: u64,
pub transparency_group_count: u32,
pub estimated_peak_bytes: u64,
pub estimated_image_decode_peak_bytes: u64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PageBounds {
pub crop: Rect,
pub rotate: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum PaintOrigin {
#[default]
PageContent = 0,
FormXObject = 1,
AnnotationAppearance = 2,
TilingPatternCell = 3,
Type3Glyph = 4,
SoftMaskContent = 5,
}
impl PaintOrigin {
pub fn name(self) -> &'static str {
match self {
Self::PageContent => "page-content",
Self::FormXObject => "form-xobject",
Self::AnnotationAppearance => "annotation-appearance",
Self::TilingPatternCell => "tiling-pattern-cell",
Self::Type3Glyph => "type3-glyph",
Self::SoftMaskContent => "soft-mask-content",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum PaintLeaf {
#[default]
Unpainted = 0,
Path = 1,
Shading = 2,
TilingPattern = 3,
Text = 4,
Image = 5,
}
impl PaintLeaf {
pub fn name(self) -> &'static str {
match self {
Self::Unpainted => "unpainted",
Self::Path => "path",
Self::Shading => "shading",
Self::TilingPattern => "tiling-pattern",
Self::Text => "text",
Self::Image => "image",
}
}
}
#[derive(Debug, Clone)]
pub enum DisplayOp {
Save,
Restore,
ConcatTransform(Matrix),
PushClip {
path: PathId,
rule: FillRule,
},
PushClipText {
runs: Box<[GlyphRunId]>,
},
PopClip,
FillPath {
path: PathId,
paint: PaintId,
rule: FillRule,
alpha: f32,
blend: BlendMode,
},
StrokePath {
path: PathId,
paint: PaintId,
style: StrokeStyleId,
alpha: f32,
blend: BlendMode,
},
DrawGlyphRun {
run: GlyphRunId,
paint: PaintId,
alpha: f32,
blend: BlendMode,
stroke: Option<GlyphStroke>,
},
DrawImage {
image: ImageId,
paint: PaintId,
transform: Matrix,
alpha: f32,
blend: BlendMode,
},
BeginTransparencyGroup {
group: TransparencyGroupId,
},
EndTransparencyGroup,
ApplySoftMask {
mask: Option<MaskId>,
},
DrawShading {
shading: ShadingId,
transform: Matrix,
},
BeginSoftMask {
kind: MaskKind,
transfer: Option<TransferLut>,
},
EndSoftMask,
ClearSoftMask,
BeginPaintOrigin(PaintOrigin),
EndPaintOrigin,
}
#[derive(Debug, Clone)]
pub struct CompiledPage {
pub schema_version: u32,
pub bounds: PageBounds,
pub content_bounds: Option<Rect>,
pub operations: Arc<[DisplayOp]>,
pub paths: Arc<[PathData]>,
pub paints: Arc<[Paint]>,
pub stroke_styles: Arc<[StrokeStyle]>,
pub glyph_runs: Arc<[GlyphRun]>,
pub fonts: Arc<[FontResource]>,
pub images: Arc<[ImageIr]>,
pub masks: Arc<[MaskResource]>,
pub groups: Arc<[TransparencyGroup]>,
pub shadings: Arc<[ShadingResource]>,
pub tilings: Arc<[TilingPattern]>,
pub features: PageFeatures,
pub complexity: PageComplexity,
}
impl CompiledPage {
pub fn debug_dump(&self) -> String {
use std::fmt::Write as _;
let mut o = String::new();
let b = &self.bounds.crop;
let _ = writeln!(o, "CompiledPage schema={}", self.schema_version);
let _ = writeln!(
o,
"bounds [{} {} {} {}] rotate {}",
g(b.x0),
g(b.y0),
g(b.x1),
g(b.y1),
self.bounds.rotate
);
let flags: Vec<&str> = self.features.iter_names().map(|(n, _)| n).collect();
let _ = writeln!(
o,
"features: {}",
if flags.is_empty() {
"none".into()
} else {
flags.join("|")
}
);
let c = &self.complexity;
let _ = writeln!(
o,
"complexity: ops={} segments={} glyphs={} image_pixels={} groups={} peak_bytes={} image_decode_peak_bytes={}",
c.operation_count,
c.path_segment_count,
c.glyph_count,
c.image_pixels,
c.transparency_group_count,
c.estimated_peak_bytes,
c.estimated_image_decode_peak_bytes
);
let _ = writeln!(o, "operations:");
for op in self.operations.iter() {
let _ = writeln!(o, " {}", fmt_op(op));
}
dump_table(&mut o, "paths", &self.paths, |p| {
format!("verbs={} points={}", p.verbs.len(), p.points.len())
});
dump_table(&mut o, "paints", &self.paints, fmt_paint);
dump_table(&mut o, "stroke_styles", &self.stroke_styles, |s| {
format!(
"width={} cap={:?} join={:?} miter={} dash=[{}] phase={}",
g(s.width),
s.cap,
s.join,
g(s.miter_limit),
s.dash_pattern
.iter()
.map(|d| g(*d))
.collect::<Vec<_>>()
.join(" "),
g(s.dash_phase)
)
});
dump_table(&mut o, "glyph_runs", &self.glyph_runs, |r| {
format!(
"font#{} size {} mode {} glyphs {}",
r.font.0,
g(r.font_size),
r.render_mode,
r.glyphs.len()
)
});
dump_table(&mut o, "fonts", &self.fonts, |f| {
format!(
"key {}:{}:{} program_bytes={}",
f.key.object_number,
f.key.generation,
f.key.variant,
f.program.len()
)
});
dump_table(&mut o, "images", &self.images, |i| {
format!(
"{}x{} bpc={} stencil={} interp={:?} decoded={} smask={}",
i.width,
i.height,
i.bits_per_component,
i.is_stencil,
i.interpolation,
i.samples.is_some(),
i.smask.is_some()
)
});
dump_table(&mut o, "groups", &self.groups, |gr| {
format!(
"isolated={} knockout={} opacity={} blend={:?} bounds [{} {} {} {}]",
gr.isolated,
gr.knockout,
g(gr.opacity as f64),
gr.blend,
g(gr.bounds.x0),
g(gr.bounds.y0),
g(gr.bounds.x1),
g(gr.bounds.y1)
)
});
dump_table(&mut o, "shadings", &self.shadings, |s| match &s.kind {
ShadingKind::Axial { extend, ramp, .. } => {
format!(
"type{} axial extend=[{} {}] ramp={}",
s.shading_type,
extend[0],
extend[1],
ramp.len()
)
}
ShadingKind::Radial { extend, ramp, .. } => {
format!(
"type{} radial extend=[{} {}] ramp={}",
s.shading_type,
extend[0],
extend[1],
ramp.len()
)
}
ShadingKind::Unsupported { .. } => format!("type{} unsupported", s.shading_type),
ShadingKind::MeshTriangles { triangles, .. } => {
format!("type{} mesh triangles={}", s.shading_type, triangles.len())
}
ShadingKind::MeshPatches { patches, .. } => {
format!("type{} mesh patches={}", s.shading_type, patches.len())
}
ShadingKind::FunctionGrid { grid_w, grid_h, .. } => {
format!("type{} function grid {}x{}", s.shading_type, grid_w, grid_h)
}
});
dump_table(&mut o, "tilings", &self.tilings, |t| {
format!(
"uncolored={} step=[{} {}] ops={}",
t.uncolored,
g(t.x_step as f64),
g(t.y_step as f64),
t.cell.operations.len()
)
});
o
}
pub fn empty(bounds: PageBounds) -> Self {
Self {
schema_version: IR_SCHEMA_VERSION,
bounds,
content_bounds: None,
operations: Arc::from([]),
paths: Arc::from([]),
paints: Arc::from([]),
stroke_styles: Arc::from([]),
glyph_runs: Arc::from([]),
fonts: Arc::from([]),
images: Arc::from([]),
masks: Arc::from([]),
groups: Arc::from([]),
shadings: Arc::from([]),
tilings: Arc::from([]),
features: PageFeatures::empty(),
complexity: PageComplexity::default(),
}
}
}
fn g(v: f64) -> String {
if v == 0.0 {
return "0".to_string();
}
if v.fract() == 0.0 && v.abs() < 1e15 {
return format!("{}", v as i64);
}
format!("{v}")
}
fn dump_table<T>(o: &mut String, name: &str, items: &[T], fmt: impl Fn(&T) -> String) {
use std::fmt::Write as _;
if items.is_empty() {
return;
}
let _ = writeln!(o, "{name}:");
for (i, item) in items.iter().enumerate() {
let _ = writeln!(o, " #{i} {}", fmt(item));
}
}
fn fmt_matrix(m: &Matrix) -> String {
format!(
"[{} {} {} {} {} {}]",
g(m.a),
g(m.b),
g(m.c),
g(m.d),
g(m.e),
g(m.f)
)
}
fn fmt_paint(p: &Paint) -> String {
match p {
Paint::Solid(c) => format!(
"solid rgba({}, {}, {}, {})",
g(c.r as f64),
g(c.g as f64),
g(c.b as f64),
g(c.a as f64)
),
Paint::Pattern { tiling, .. } => format!("tiling#{}", tiling.0),
Paint::Shading { shading, .. } => format!("shading#{}", shading.0),
}
}
fn fmt_op(op: &DisplayOp) -> String {
match op {
DisplayOp::Save => "save".into(),
DisplayOp::Restore => "restore".into(),
DisplayOp::ConcatTransform(m) => format!("concat {}", fmt_matrix(m)),
DisplayOp::PushClip { path, rule } => format!("push-clip path#{} {:?}", path.0, rule),
DisplayOp::PushClipText { runs } => {
let ids: Vec<String> = runs.iter().map(|r| format!("run#{}", r.0)).collect();
format!("push-clip-text [{}]", ids.join(" "))
}
DisplayOp::PopClip => "pop-clip".into(),
DisplayOp::FillPath {
path,
paint,
rule,
alpha,
blend,
} => format!(
"fill path#{} paint#{} {:?} alpha {} {:?}",
path.0,
paint.0,
rule,
g(*alpha as f64),
blend
),
DisplayOp::StrokePath {
path,
paint,
style,
alpha,
blend,
} => format!(
"stroke path#{} paint#{} style#{} alpha {} {:?}",
path.0,
paint.0,
style.0,
g(*alpha as f64),
blend
),
DisplayOp::DrawGlyphRun {
run,
paint,
alpha,
blend,
stroke,
} => {
let s = match stroke {
Some(gs) => format!(
" stroke(paint#{} style#{} alpha {})",
gs.paint.0,
gs.style.0,
g(gs.alpha as f64)
),
None => String::new(),
};
format!(
"draw-glyph-run run#{} paint#{} alpha {} {:?}{s}",
run.0,
paint.0,
g(*alpha as f64),
blend
)
}
DisplayOp::DrawImage {
image,
paint,
transform,
alpha,
blend,
} => format!(
"draw-image image#{} paint#{} {} alpha {} {:?}",
image.0,
paint.0,
fmt_matrix(transform),
g(*alpha as f64),
blend
),
DisplayOp::BeginTransparencyGroup { group } => format!("begin-group group#{}", group.0),
DisplayOp::EndTransparencyGroup => "end-group".into(),
DisplayOp::ApplySoftMask { mask } => match mask {
Some(m) => format!("apply-soft-mask mask#{}", m.0),
None => "apply-soft-mask none".into(),
},
DisplayOp::DrawShading { shading, transform } => {
format!(
"draw-shading shading#{} {}",
shading.0,
fmt_matrix(transform)
)
}
DisplayOp::BeginPaintOrigin(o) => format!("begin-paint-origin {}", o.name()),
DisplayOp::EndPaintOrigin => "end-paint-origin".into(),
DisplayOp::BeginSoftMask { kind, transfer } => {
if transfer.is_some() {
format!("begin-soft-mask {kind:?} transfer=lut256")
} else {
format!("begin-soft-mask {kind:?}")
}
}
DisplayOp::EndSoftMask => "end-soft-mask".into(),
DisplayOp::ClearSoftMask => "clear-soft-mask".into(),
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use super::*;
const fn assert_send_sync<T: Send + Sync>() {}
const _: () = assert_send_sync::<CompiledPage>();
#[test]
fn empty_page_is_valid() {
let page = CompiledPage::empty(PageBounds {
crop: Rect {
x0: 0.0,
y0: 0.0,
x1: 612.0,
y1: 792.0,
},
rotate: 0,
});
assert_eq!(page.schema_version, IR_SCHEMA_VERSION);
assert!(page.operations.is_empty());
assert!(page.features.is_empty());
}
#[test]
fn shared_bytes_preserves_the_vec_data_allocation() {
let bytes = vec![1, 2, 3, 4, 5];
let allocation = bytes.as_ptr();
let shared = SharedBytes::from(bytes);
assert_eq!(shared.as_ptr(), allocation);
assert_eq!(shared.as_slice(), &[1, 2, 3, 4, 5]);
assert_eq!(shared.clone().as_ptr(), allocation);
}
}