Skip to content

Commit

Permalink
Replace u32 with core::num::NonZeroU32
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed May 27, 2021
1 parent 4f774f2 commit 0e769f7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ where
/// # Errors
///
/// If the returned value cannot be properly decoded.
pub fn rent_status<T>(at_refcount: Option<u32>) -> Result<RentStatus<T>>
pub fn rent_status<T>(at_refcount: Option<core::num::NonZeroU32>) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub trait TypedEnvBackend: EnvBackend {
/// For more details visit: [`RentStatus`][`crate::RentStatus`]
fn rent_status<T: Environment>(
&mut self,
at_refcount: Option<u32>,
at_refcount: Option<core::num::NonZeroU32>,
) -> Result<RentStatus<T>>;

/// Returns the current block number.
Expand Down
5 changes: 4 additions & 1 deletion crates/env/src/engine/experimental_off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ impl TypedEnvBackend for EnvInstance {
unimplemented!("off-chain environment does not support rent params")
}

fn rent_status<T>(&mut self, _at_refcount: Option<u32>) -> Result<RentStatus<T>>
fn rent_status<T>(
&mut self,
_at_refcount: Option<core::num::NonZeroU32>,
) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
5 changes: 4 additions & 1 deletion crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ impl TypedEnvBackend for EnvInstance {
})
}

fn rent_status<T>(&mut self, _at_refcount: Option<u32>) -> Result<RentStatus<T>>
fn rent_status<T>(
&mut self,
_at_refcount: Option<core::num::NonZeroU32>,
) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
4 changes: 2 additions & 2 deletions crates/env/src/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ pub fn rent_params(output: &mut &mut [u8]) {
extract_from_slice(output, output_len as usize);
}

pub fn rent_status(at_refcount: Option<u32>, output: &mut &mut [u8]) {
pub fn rent_status(at_refcount: Option<core::num::NonZeroU32>, output: &mut &mut [u8]) {
let mut output_len = output.len() as u32;
{
unsafe {
sys::seal_rent_status(
at_refcount.unwrap_or(0),
at_refcount.map_or(0, |rc| rc.get()),
Ptr32Mut::from_slice(output),
Ptr32Mut::from_ref(&mut output_len),
)
Expand Down
5 changes: 4 additions & 1 deletion crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ impl TypedEnvBackend for EnvInstance {
self.get_property::<RentParams<T>>(ext::rent_params)
}

fn rent_status<T>(&mut self, at_refcount: Option<u32>) -> Result<RentStatus<T>>
fn rent_status<T>(
&mut self,
at_refcount: Option<core::num::NonZeroU32>,
) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
5 changes: 4 additions & 1 deletion crates/lang/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ where
/// # Note
///
/// For more details visit: [`ink_env::RentStatus`]
pub fn rent_status(self, at_refcount: Option<u32>) -> RentStatus<T> {
pub fn rent_status(
self,
at_refcount: Option<core::num::NonZeroU32>,
) -> RentStatus<T> {
ink_env::rent_status::<T>(at_refcount)
.expect("couldn't decode contract rent params")
}
Expand Down

0 comments on commit 0e769f7

Please sign in to comment.