fn align_mem_slot(range: AddressRange, alignment: u64) -> Result<AddressRange> {
        let aligned_addr = range
            .base
            .align_up(alignment)
            .chain_err(|| ErrorKind::AddrAlignUp(range.base.raw_value(), alignment))?;

        let aligned_size = range
            .size
            .checked_sub(aligned_addr.offset_from(range.base))
            .and_then(|sz| round_down(sz, alignment))
            .filter(|&sz| sz > 0_u64)
            .chain_err(||
                format!("Mem slot size is zero after aligned, addr 0x{:X}, size 0x{:X}, alignment 0x{:X}",
                    range.base.raw_value(), range.size, alignment)
            )?;

        Ok(AddressRange::new(aligned_addr, aligned_size))
    }
/// Align a piece of memory segment according to `alignment`,
/// return AddressRange after aligned.
///
/// # Arguments
///
/// * `range` - One piece of memory segment.
/// * `alignment` - Alignment base.
///
/// # Errors
///
/// Return Error if Memslot size is zero after aligned.
Align a piece of memory segment according to `alignment`,
return AddressRange after aligned.
Align a piece of memory segment according to ` alignment ` return AddressRange after aligned .
fn align_mem_slot(range: AddressRange, alignment: u64) -> Result<AddressRange> {
        let aligned_addr = range
            .base
            .align_up(alignment)
            .chain_err(|| ErrorKind::AddrAlignUp(range.base.raw_value(), alignment))?;
        let aligned_size = range
            .size
            .checked_sub(aligned_addr.offset_from(range.base))
            .and_then(|sz| round_down(sz, alignment))
            .filter(|&sz| sz > 0_u64)
            .chain_err(||
                format!("Mem slot size is zero after aligned, addr 0x{:X}, size 0x{:X}, alignment 0x{:X}",
                    range.base.raw_value(), range.size, alignment)
            )?;
        Ok(AddressRange::new(aligned_addr, aligned_size))
    }
fn align_mem_slot ( range : AddressRange , alignment : u64 ) -> Result < AddressRange > { let aligned_addr = range . base . align_up ( alignment ) . chain_err ( | | ErrorKind :: AddrAlignUp ( range . base . raw_value ( ) , alignment ) ) ? ; let aligned_size = range . size . checked_sub ( aligned_addr . offset_from ( range . base ) ) . and_then ( | sz | round_down ( sz , alignment ) ) . filter ( | & sz | sz > 0_u64 ) . chain_err ( | | format ! ( " " range base raw_value ( ) range size alignment ) ) ? ; Ok ( AddressRange :: new ( aligned_addr , aligned_size ) ) }
Align a piece of memory segment according to `alignment`,
return AddressRange after aligned.
Align a piece of memory segment according to ` alignment ` return AddressRange after aligned .
range
AddressRange
alignment
u64
range
AddressRange
alignment
u64
errors
Return Error if Memslot size is zero after aligned.
Return Error if Memslot size is zero after aligned .