pub fn write(content: &[u8], offset: u32) {
    let min_len = u32::try_from(content.len() + usize::try_from(offset).unwrap())
        .expect("stable::write: content size + offset is too large");

    let current_pages = unsafe { ic0::stable_size() };

    let old_len = if current_pages == 0 { 0 } else { length() };
    let new_len = std::cmp::max(old_len, min_len);

    if new_len > old_len {
        ensure_capacity(new_len);
    }

    // Don't call stable_write unless we have data to write. This also avoids an
    // error when offset=0 and content is empty: in this case we don't allocate
    // any pages so write fails.
    if content.is_empty() {
        return;
    }

    unsafe {
        ic0::stable_write(
            LENGTH_BYTES + offset,
            content.as_ptr() as u32,
            content.len() as u32,
        );
    }

    if new_len > old_len {
        set_length(new_len);
    }
}
/// Writes `content` to the given offset in the stable memory
Writes `content` to the given offset in the stable memory
Writes ` content ` to the given offset in the stable memory
pub fn write(content: &[u8], offset: u32) {
    let min_len = u32::try_from(content.len() + usize::try_from(offset).unwrap())
        .expect("stable::write: content size + offset is too large");
    let current_pages = unsafe { ic0::stable_size() };
    let old_len = if current_pages == 0 { 0 } else { length() };
    let new_len = std::cmp::max(old_len, min_len);
    if new_len > old_len {
        ensure_capacity(new_len);
    }
    // Don't call stable_write unless we have data to write. This also avoids an
    // error when offset=0 and content is empty: in this case we don't allocate
    // any pages so write fails.
    if content.is_empty() {
        return;
    }
    unsafe {
        ic0::stable_write(
            LENGTH_BYTES + offset,
            content.as_ptr() as u32,
            content.len() as u32,
        );
    }
    if new_len > old_len {
        set_length(new_len);
    }
}
pub fn write ( content : & [ u8 ] , offset : u32 ) { let min_len = u32 :: try_from ( content . len ( ) + usize :: try_from ( offset ) . unwrap ( ) ) . expect ( " " ) ; let current_pages = unsafe { ic0 :: stable_size ( ) } ; let old_len = if current_pages == 0 { 0 } else { length ( ) } ; let new_len = std :: cmp :: max ( old_len , min_len ) ; if new_len > old_len { ensure_capacity ( new_len ) ; } // Don't call stable_write unless we have data to write. This also avoids an // error when offset=0 and content is empty: in this case we don't allocate // any pages so write fails. if content . is_empty ( ) { return ; } unsafe { ic0 :: stable_write ( LENGTH_BYTES + offset , content . as_ptr ( ) as u32 , content . len ( ) as u32 , ) ; } if new_len > old_len { set_length ( new_len ) ; } }
Writes `content` to the given offset in the stable memory
Writes ` content ` to the given offset in the stable memory
content
&[u8]
offset
u32
content
&[u8]
offset
u32