pub struct FlashBlock { /* private fields */ }Available on
target_os=none only.Expand description
Type of a FlashArray block, with methods such as load, save, and clear.
See FlashArray for usage examples.
Implementations§
Source§impl FlashBlock
impl FlashBlock
Sourcepub fn load<T>(&mut self) -> Result<Option<T>>where
T: Serialize + for<'de> Deserialize<'de>,
pub fn load<T>(&mut self) -> Result<Option<T>>where
T: Serialize + for<'de> Deserialize<'de>,
Load data stored in this block.
See FlashArray for usage examples.
Examples found in repository?
examples/flash.rs (line 58)
40async fn inner_main(_spawner: Spawner) -> Result<()> {
41 info!("Flash Storage Example");
42
43 // Initialize hardware
44 let p = embassy_rp::init(Default::default());
45
46 // Initialize Flash device
47 let [_, _, _, mut string_block, mut config_block] = FlashArray::<5>::new(p.FLASH)?;
48
49 info!("Part 1: Storing data to flash");
50 string_block.save(&String::<64>::try_from("Hello, Flash Storage!")?)?;
51 config_block.save(&SensorConfig {
52 name: String::<32>::try_from("Temperature")?,
53 sample_rate_hz: 1000,
54 enabled: true,
55 })?;
56
57 info!("Part 2: Reading data from flash");
58 let string: Option<String<64>> = string_block.load()?;
59 assert!(string.as_deref() == Some("Hello, Flash Storage!"));
60 let config: Option<SensorConfig> = config_block.load()?;
61 assert!(
62 config
63 == Some(SensorConfig {
64 name: String::<32>::try_from("Temperature")?,
65 sample_rate_hz: 1000,
66 enabled: true,
67 })
68 );
69
70 info!("Part 3: Reading a different type counts as empty");
71 // Try to read the string block as a SensorConfig
72 let wrong_type_result: Option<SensorConfig> = string_block.load()?;
73 assert!(wrong_type_result.is_none());
74
75 info!("Part 4: Clearing flash blocks");
76 string_block.clear()?;
77 config_block.clear()?;
78
79 info!("Part 5: Verifying cleared blocks");
80 let string: Option<String<64>> = string_block.load()?;
81 assert!(string.is_none());
82 let config: Option<SensorConfig> = config_block.load()?;
83 assert!(config.is_none());
84
85 info!("Flash Storage Example Complete!");
86 loop {
87 embassy_time::Timer::after_secs(1).await;
88 }
89}Sourcepub fn save<T>(&mut self, value: &T) -> Result<()>where
T: Serialize + for<'de> Deserialize<'de>,
pub fn save<T>(&mut self, value: &T) -> Result<()>where
T: Serialize + for<'de> Deserialize<'de>,
Save data to this block.
See FlashArray for usage examples.
Examples found in repository?
examples/flash.rs (line 50)
40async fn inner_main(_spawner: Spawner) -> Result<()> {
41 info!("Flash Storage Example");
42
43 // Initialize hardware
44 let p = embassy_rp::init(Default::default());
45
46 // Initialize Flash device
47 let [_, _, _, mut string_block, mut config_block] = FlashArray::<5>::new(p.FLASH)?;
48
49 info!("Part 1: Storing data to flash");
50 string_block.save(&String::<64>::try_from("Hello, Flash Storage!")?)?;
51 config_block.save(&SensorConfig {
52 name: String::<32>::try_from("Temperature")?,
53 sample_rate_hz: 1000,
54 enabled: true,
55 })?;
56
57 info!("Part 2: Reading data from flash");
58 let string: Option<String<64>> = string_block.load()?;
59 assert!(string.as_deref() == Some("Hello, Flash Storage!"));
60 let config: Option<SensorConfig> = config_block.load()?;
61 assert!(
62 config
63 == Some(SensorConfig {
64 name: String::<32>::try_from("Temperature")?,
65 sample_rate_hz: 1000,
66 enabled: true,
67 })
68 );
69
70 info!("Part 3: Reading a different type counts as empty");
71 // Try to read the string block as a SensorConfig
72 let wrong_type_result: Option<SensorConfig> = string_block.load()?;
73 assert!(wrong_type_result.is_none());
74
75 info!("Part 4: Clearing flash blocks");
76 string_block.clear()?;
77 config_block.clear()?;
78
79 info!("Part 5: Verifying cleared blocks");
80 let string: Option<String<64>> = string_block.load()?;
81 assert!(string.is_none());
82 let config: Option<SensorConfig> = config_block.load()?;
83 assert!(config.is_none());
84
85 info!("Flash Storage Example Complete!");
86 loop {
87 embassy_time::Timer::after_secs(1).await;
88 }
89}Sourcepub fn clear(&mut self) -> Result<()>
pub fn clear(&mut self) -> Result<()>
Clear this block.
Examples found in repository?
examples/flash.rs (line 76)
40async fn inner_main(_spawner: Spawner) -> Result<()> {
41 info!("Flash Storage Example");
42
43 // Initialize hardware
44 let p = embassy_rp::init(Default::default());
45
46 // Initialize Flash device
47 let [_, _, _, mut string_block, mut config_block] = FlashArray::<5>::new(p.FLASH)?;
48
49 info!("Part 1: Storing data to flash");
50 string_block.save(&String::<64>::try_from("Hello, Flash Storage!")?)?;
51 config_block.save(&SensorConfig {
52 name: String::<32>::try_from("Temperature")?,
53 sample_rate_hz: 1000,
54 enabled: true,
55 })?;
56
57 info!("Part 2: Reading data from flash");
58 let string: Option<String<64>> = string_block.load()?;
59 assert!(string.as_deref() == Some("Hello, Flash Storage!"));
60 let config: Option<SensorConfig> = config_block.load()?;
61 assert!(
62 config
63 == Some(SensorConfig {
64 name: String::<32>::try_from("Temperature")?,
65 sample_rate_hz: 1000,
66 enabled: true,
67 })
68 );
69
70 info!("Part 3: Reading a different type counts as empty");
71 // Try to read the string block as a SensorConfig
72 let wrong_type_result: Option<SensorConfig> = string_block.load()?;
73 assert!(wrong_type_result.is_none());
74
75 info!("Part 4: Clearing flash blocks");
76 string_block.clear()?;
77 config_block.clear()?;
78
79 info!("Part 5: Verifying cleared blocks");
80 let string: Option<String<64>> = string_block.load()?;
81 assert!(string.is_none());
82 let config: Option<SensorConfig> = config_block.load()?;
83 assert!(config.is_none());
84
85 info!("Flash Storage Example Complete!");
86 loop {
87 embassy_time::Timer::after_secs(1).await;
88 }
89}Auto Trait Implementations§
impl Freeze for FlashBlock
impl !RefUnwindSafe for FlashBlock
impl Send for FlashBlock
impl Sync for FlashBlock
impl Unpin for FlashBlock
impl !UnwindSafe for FlashBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Casts the value.
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.