// Copyright 2017 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use std::fmt; use std::ops::Deref; use std::rc::Rc; #[derive(Clone)] pub struct RcSlice { data: Rc>, offset: u32, len: u32, } impl RcSlice { pub fn new(vec: Vec) -> Self { RcSlice { offset: 0, len: vec.len() as u32, data: Rc::new(vec.into_boxed_slice()), } } } impl Deref for RcSlice { type Target = [T]; fn deref(&self) -> &[T] { &self.data[self.offset as usize .. (self.offset + self.len) as usize] } } impl fmt::Debug for RcSlice { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(self.deref(), f) } }