Skip to content

Commit c4b1b41

Browse files
committed
Ensure disambiguation for default call
1 parent 3a24665 commit c4b1b41

File tree

7 files changed

+70
-12
lines changed

7 files changed

+70
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All changes to this project will be noted in this file.
44

5+
## Version 0.1.3
6+
7+
Internal fixes for `default` calls
8+
59
## Version 0.1.2
610

711
Fixed docstrings

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ bagel = "0.1"
1313

1414
## What bagel can do
1515

16-
- `Ctor`: Derive constructors
17-
- `Gtor`: Derive getters
18-
- `Stor`: Derive setters
19-
- `Constdef`: Derive constant, compile-time default implementations
2016
- `def`: Use the [default declaration syntax](#default-declaration-syntax)
17+
- `Ctor`: Derive constructors:
18+
- Full lifetimes, generics and where clause support
19+
- `#[phantom]`: Auto elide `PhantomData` fields
20+
- `#[ctor_const]`: Make the constructor a `const fn`
21+
- `Gtor`: Derive getters:
22+
- Full lifetimes, generics and where clause support
23+
- Advanced attributes: `#[gtor_const]`, `#[gtor_copy]`, `#[gtor_skip]`, `#[phantom]` and `#[gtor]`
24+
- `Stor`: Derive setters
25+
- Full lifetimes, generics and where clause support
26+
- Skip setter with `#[stor_skip]` or `#[phantom]`
27+
- `Constdef`: Derive constant, compile-time default implementations. See [an example here](#constdef-example)
2128

2229
## Default declaration syntax
2330

@@ -65,6 +72,29 @@ assert_eq!(myoven.items_to_bake[3], "pie");
6572
assert_eq!(myoven.people_buffer.len(), 2);
6673
```
6774

75+
## `Constdef` example
76+
77+
```rust
78+
use bagel::Constdef;
79+
80+
#[derive(Constdef)]
81+
struct Port {
82+
requests: usize,
83+
admin: bool,
84+
}
85+
86+
#[derive(Constdef)]
87+
struct PortLogger {
88+
ports: [Port; 65536],
89+
root_pid: usize,
90+
}
91+
92+
const PORT_LOGGER: PortLogger = PortLogger::default();
93+
94+
assert_eq!(PORT_LOGGER.ports[0].requests, 0);
95+
assert_eq!(PORT_LOGGER.ports[65535].admin, false);
96+
```
97+
6898
## License
6999

70100
The `dough` and `bagel` libraries are distributed under the [Apache-2.0 License](./LICENSE).

bagel/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "Apache-2.0"
77
name = "bagel"
88
readme = "../README.md"
99
repository = "https://github.com/skytable/bagel"
10-
version = "0.1.2"
10+
version = "0.1.3"
1111

1212
[dependencies]
13-
dough = "0.1.1"
13+
dough = "0.1.3"

bagel/tests/all.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use bagel::Constdef;
2+
3+
#[derive(Constdef)]
4+
struct Port {
5+
requests: usize,
6+
admin: bool,
7+
}
8+
9+
#[derive(Constdef)]
10+
struct PortLogger {
11+
ports: [Port; 65536],
12+
root_pid: usize,
13+
}
14+
15+
const PORT_LOGGER: PortLogger = PortLogger::default();
16+
17+
#[test]
18+
fn nested_object() {
19+
assert_eq!(PORT_LOGGER.ports[0].requests, 0);
20+
assert_eq!(PORT_LOGGER.ports[65535].admin, false);
21+
assert_eq!(PORT_LOGGER.root_pid, 0);
22+
}

dough/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dough"
3-
version = "0.1.1"
3+
version = "0.1.3"
44
edition = "2018"
55
license = "Apache-2.0"
66
description = "Internal macros for the bagel crate"

dough/src/constdef/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ fn generate_unnamed(fields: Vec<UnnamedFieldInfo<'_>>, ast: &DeriveInput) -> Tok
6060
}
6161
impl #impl_gen ::core::default::Default for #struct_name #ty_gen #where_clause {
6262
fn default() -> Self {
63-
Self::default()
63+
::bagel::Constdef::DEFAULT
6464
}
6565
}
6666
impl #impl_gen ::bagel::Constdef for #struct_name #ty_gen #where_clause {
67-
const DEFAULT: Self = Self::default();
67+
const DEFAULT: Self = #struct_name::default();
6868
}
6969
};
7070
tokens.into()
@@ -116,11 +116,11 @@ fn generate_named(fields: Vec<NamedFieldInfo<'_>>, ast: &DeriveInput) -> TokenSt
116116
}
117117
impl #impl_gen ::core::default::Default for #struct_name #ty_gen #where_clause {
118118
fn default() -> Self {
119-
Self::default()
119+
::bagel::Constdef::DEFAULT
120120
}
121121
}
122122
impl #impl_gen ::bagel::Constdef for #struct_name #ty_gen #where_clause {
123-
const DEFAULT: Self = Self::default();
123+
const DEFAULT: Self = #struct_name::default();
124124
}
125125
};
126126
tokens.into()

dough/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! # `dough`
22
//!
33
//! Consider using the [`bagel`](https://crates.io/crates/bagel) crate. The `dough` crate provides
4-
//! supporting macros for bagel
4+
//! supporting macros for bagel.
5+
//!
6+
//! WARNING: Do not rely on the API of this crate
57
//!
68
79
use proc_macro::TokenStream;

0 commit comments

Comments
 (0)