Skip to content

Commit

Permalink
Auto merge of #55 - japaric:late-resources, r=japaric
Browse files Browse the repository at this point in the history
[RFC] rename LateResourceValues to LateResources

After writing `LateResourceValues` several times I now think it's too long to type. I'd like that
struct to be renamed to `LateResources`. I don't think there would be a loss in readability with the
rename because you can think of "late resources" as resources that "don't exist" until `init` ends
instead of as resources that are not initialized after `init` ends -- the second meaning maps better
to `LateResourceValues`.

This would be a breaking-change but we are moving to v0.3.0 due to #50 in any case.

cc jonas-schievink
  • Loading branch information
homunkulus committed Dec 9, 2017
2 parents e78ca98 + 512091e commit 0a0e0e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ app! {
},
}

fn init(p: init::Peripherals) -> init::LateResourceValues {
init::LateResourceValues {
fn init(p: init::Peripherals) -> init::LateResources {
init::LateResources {
GPIOA: p.device.GPIOA,
SPI1: p.device.SPI1,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/late-resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ app! {
}

// The signature of `init` is now required to have a specific return type.
fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResourceValues {
fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResources {
// `init::Resources` does not contain `IP_ADDRESS`, since it is not yet
// initialized.
//_r.IP_ADDRESS; // doesn't compile

// ...obtain value for IP_ADDRESS from EEPROM/DHCP...
let ip_address = 0x7f000001;

init::LateResourceValues {
init::LateResources {
// This struct will contain fields for all resources with omitted
// initializers.
IP_ADDRESS: ip_address,
Expand Down
6 changes: 3 additions & 3 deletions macros/src/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
root.push(quote! {
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
pub struct _initLateResourceValues {
pub struct _initLateResources {
#(#fields)*
}
});

mod_items.push(quote! {
pub use ::_initLateResourceValues as LateResourceValues;
pub use ::_initLateResources as LateResources;
});

// `init` must return the initialized resources
ret = Some(quote!( -> ::init::LateResourceValues));
ret = Some(quote!( -> ::init::LateResources));
}

root.push(quote! {
Expand Down
4 changes: 2 additions & 2 deletions src/examples/_5_late_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@
//! }
//!
//! // The signature of `init` is now required to have a specific return type.
//! fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResourceValues {
//! fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResources {
//! // `init::Resources` does not contain `IP_ADDRESS`, since it is not yet
//! // initialized.
//! //_r.IP_ADDRESS; // doesn't compile
//!
//! // ...obtain value for IP_ADDRESS from EEPROM/DHCP...
//! let ip_address = 0x7f000001;
//!
//! init::LateResourceValues {
//! init::LateResources {
//! // This struct will contain fields for all resources with omitted
//! // initializers.
//! IP_ADDRESS: ip_address,
Expand Down
4 changes: 2 additions & 2 deletions tests/cfail/late-resource-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ app! {
},
}

fn init(_p: init::Peripherals, r: init::Resources) -> init::LateResourceValues {
fn init(_p: init::Peripherals, r: init::Resources) -> init::LateResources {
// Try to use a resource that's not yet initialized:
r.LATE;
//~^ error: no field `LATE`

init::LateResourceValues {
init::LateResources {
LATE: 0,
}
}
Expand Down

0 comments on commit 0a0e0e2

Please sign in to comment.