Skip to content

Commit

Permalink
Merge branch 'main' into v0.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Nov 1, 2023
2 parents fa7464c + 1d4865c commit f7284bc
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .rustme/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Configuration(
),
"ref-name": (
default: "main",
release: "v0.2.0",
release: "v0.2.1",
),
"map": (
default: "https://khonsulabs.github.io/kempt/main/kempt/struct.Map.html",
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## v0.2.1

### Added

- `Map::get_mut` and `Map::get_field_mut` provide exclusive access to the fields
that are found.
- `Set::remove_member` removes a member by index.
- `Set` now implements `Debug`, `Ord`, `Eq`, and `Clone`.

## v0.2.0

### Added

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ our only requirements for contributing:
- All contributors must uphold the standards of our [Code of
Conduct](./CODE_OF_CONDUCT.md).

The rest of this document are recommendations/guidelines to help consistency and
The rest of this document is recommendations/guidelines to help consistency and
communication within our projects.

## Creating Issues
Expand Down Expand Up @@ -45,7 +45,7 @@ working on it. This will help prevent duplicated efforts.

If you begin working on something but need some assistance, don't hesitate to
reach out inside of the issue, on [our
forums](https://community.khonsulabs.com/), or [our
forums](https://community.khonsulabs.com/), or in [our
Discord](https://discord.khonsulabs.com/). We will do our best to help you.

### Project-specific requirements
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kempt"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.65.0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ their target hardware rather than rely on these benchmark results.

## Open-source Licenses

This project, like all projects from [Khonsu Labs](https://khonsulabs.com/), are
open-source. This repository is available under the [MIT License](./LICENSE-MIT)
or the [Apache License 2.0](./LICENSE-APACHE).
This project, like all projects from [Khonsu Labs](https://khonsulabs.com/), is open-source.
This repository is available under the [MIT License](./LICENSE-MIT) or the
[Apache License 2.0](./LICENSE-APACHE).

To learn more about contributing, please see [CONTRIBUTING.md](./CONTRIBUTING.md).
23 changes: 22 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,17 @@ where
self.get_field(key).map(|field| &field.value)
}

/// Returns the value associated with `key`, if found.
/// Returns a mutable value associated with `key`, if found.
#[inline]
pub fn get_mut<SearchFor>(&mut self, key: &SearchFor) -> Option<&mut Value>
where
Key: Sort<SearchFor>,
SearchFor: ?Sized,
{
self.get_field_mut(key).map(|field| &mut field.value)
}

/// Returns the field associated with `key`, if found.
#[inline]
pub fn get_field<SearchFor>(&self, key: &SearchFor) -> Option<&Field<Key, Value>>
where
Expand All @@ -168,6 +178,17 @@ where
self.find_key(key).ok()
}

/// Returns the a mutable reference to the field associated with `key`, if
/// found.
#[inline]
pub fn get_field_mut<SearchFor>(&mut self, key: &SearchFor) -> Option<&mut Field<Key, Value>>
where
Key: Sort<SearchFor>,
SearchFor: ?Sized,
{
self.find_key_mut(key).ok()
}

/// Returns the [`Field`] at the specified `index`, or None if the index is
/// outside of the bounds of this collection.
#[inline]
Expand Down
26 changes: 26 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::{self, Debug};

use crate::map::{self, Field, OwnedOrRef};
use crate::{Map, Sort};

Expand Down Expand Up @@ -33,6 +35,7 @@ pub type IntoIter<T> = map::IntoKeys<T, ()>;
/// assert_eq!(set.member(1), Some(&2));
/// assert_eq!(set.member(2), Some(&3));
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Set<T>(Map<T, ()>)
where
T: Ord;
Expand Down Expand Up @@ -112,6 +115,16 @@ where
self.0.field(index).map(Field::key)
}

/// Removes the member at `index`.
///
/// # Panics
///
/// A panic will occur if `index` is greater than or equal to the set's
/// length.
pub fn remove_member(&mut self, index: usize) -> T {
self.0.remove_by_index(index).into_key()
}

/// Returns the number of members in this set.
#[must_use]
pub fn len(&self) -> usize {
Expand Down Expand Up @@ -161,6 +174,19 @@ where
}
}

impl<T> Debug for Set<T>
where
T: Ord + Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_set();
for member in self {
s.entry(member);
}
s.finish()
}
}

impl<'a, T> IntoIterator for &'a Set<T>
where
T: Ord,
Expand Down

0 comments on commit f7284bc

Please sign in to comment.