RSync

Struct RSync 

Source
pub struct RSync { /* private fields */ }
Expand description

远程同步,用于计算数据的差异以及根据差异和旧数据构建出新的数据

§Examples

   let oldStr = "qwertyuiopasdfghjklzxcvbnmrrrrrrrrrrrefregrtytfessfrer";
   let newStr = "qzetyuioasdfgzjklzxcwbkmrerrrrrrrrrrrtghgtrrrrrfgsfrer";
   let oldBytes = String::from(oldStr).into_bytes();
   let newBytes = String::from(newStr).into_bytes();

   let rsync = RSync::new(5);
   let check_sums = rsync.check_sum(&oldBytes); // 根据旧数据,算出校验和
   let diffs = rsync.diff(&newBytes, check_sums); // 根据旧数据的校验和、新数据,算出新数据与旧数据的差异
   let r = rsync.sync(&oldBytes, diffs); // 根据旧数据和差异,还原为新的数据

   let s = String::from_utf8(r).expect("-----------------------------");
   assert_eq!(&s, newStr); 

Implementations§

Source§

impl RSync

Source

pub fn new(block_size: usize) -> RSync

创建远程同步实例 block_size为块大小设置,单位:字节,如果设置为0,表示使用默认值,默认值为64字节

Source

pub fn check_sum(&self, data: &[u8]) -> Vec<CheckSum>

计算校验和

Source

pub fn diff(&self, new_data: &[u8], old_check_sums: Vec<CheckSum>) -> Vec<Diff>

根据新的数据和旧的校验和,计算新旧数据的差异 返回数据差异

Source

pub fn sync(&self, old_data: &[u8], diffs: Vec<Diff>) -> Vec<u8>

同步数据 根据数据差异和旧数据,得到新数据

Auto Trait Implementations§

§

impl Freeze for RSync

§

impl RefUnwindSafe for RSync

§

impl Send for RSync

§

impl Sync for RSync

§

impl Unpin for RSync

§

impl UnwindSafe for RSync

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.