Skip to content

Commit 48f9c75

Browse files
committed
Add Copy and map_ref for SpannedValue
1 parent 525c51f commit 48f9c75

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.13.0 (May 20, 2021)
4+
5+
- Update darling to 2018 edition [#129](https://github.com/TedDriggs/darling/pull/129)
6+
- Error on duplicate fields in `#[darling(...)]` attributes [#130](https://github.com/TedDriggs/darling/pull/130)
7+
- Impl `Copy` for `SpannedValue<T: Copy>`
8+
- Add `SpannedValue::map_ref`
9+
310
## v0.13.0-beta (April 20, 2021)
411

512
- Update darling to 2018 edition [#129](https://github.com/TedDriggs/darling/pull/129)

core/src/util/spanned_value.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
/// but the user may not always explicitly set those options in their source code.
2020
/// In this case, using `Default::default()` will create an instance which points
2121
/// to `Span::call_site()`.
22-
#[derive(Debug, Clone)]
22+
#[derive(Debug, Clone, Copy)]
2323
pub struct SpannedValue<T> {
2424
value: T,
2525
span: Span,
@@ -34,6 +34,11 @@ impl<T> SpannedValue<T> {
3434
pub fn span(&self) -> Span {
3535
self.span
3636
}
37+
38+
/// Apply a mapping function to a reference to the spanned value.
39+
pub fn map_ref<U>(&self, map_fn: impl FnOnce(&T) -> U) -> SpannedValue<U> {
40+
SpannedValue::new(map_fn(&self.value), self.span)
41+
}
3742
}
3843

3944
impl<T: Default> Default for SpannedValue<T> {

0 commit comments

Comments
 (0)