Skip to content

Commit

Permalink
chore: mark ObjectKey::identifier function as deprecated
Browse files Browse the repository at this point in the history
It will be removed entirely as part of the future minor or major
release.
  • Loading branch information
martinohmann committed Oct 27, 2022
1 parent 86dda75 commit d2f5f94
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/macros.rs
Expand Up @@ -389,14 +389,17 @@ macro_rules! block_label {
/// ## Examples
///
/// ```
/// use hcl::ObjectKey;
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use hcl::{Identifier, ObjectKey};
///
/// assert_eq!(hcl::object_key!(some_identifier), ObjectKey::identifier("some_identifier"));
/// assert_eq!(hcl::object_key!(some_identifier), ObjectKey::from(Identifier::new("some_identifier")?));
/// assert_eq!(hcl::object_key!("some string"), ObjectKey::from("some string"));
///
/// let key = "some expression";
///
/// assert_eq!(hcl::object_key!((key)), ObjectKey::from("some expression"));
/// # Ok(())
/// # }
/// ```
#[macro_export]
macro_rules! object_key {
Expand Down Expand Up @@ -424,7 +427,8 @@ macro_rules! object_key {
/// ## Examples
///
/// ```
/// use hcl::{Expression, Object, ObjectKey};
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use hcl::{Expression, Identifier, Object, ObjectKey};
///
/// let other = "hello";
///
Expand All @@ -435,12 +439,14 @@ macro_rules! object_key {
/// });
///
/// let expected = Expression::Object(Object::from([
/// (ObjectKey::identifier("foo"), true.into()),
/// (ObjectKey::from(Identifier::new("foo")?), true.into()),
/// (ObjectKey::from("baz qux"), vec![1u64, 2].into()),
/// (ObjectKey::from("hello"), "world".into()),
/// ]));
///
/// assert_eq!(expression, expected);
/// # Ok(())
/// # }
/// ```
#[macro_export]
macro_rules! expression {
Expand Down
5 changes: 4 additions & 1 deletion src/ser/tests.rs
Expand Up @@ -87,7 +87,10 @@ fn serialize_body() {
)
.add_attribute(("an_object", {
Object::from([
(ObjectKey::identifier("foo"), Expression::from("bar")),
(
ObjectKey::from(Identifier::unchecked("foo")),
Expression::from("bar"),
),
(
ObjectKey::from("enabled"),
Expression::from(RawExpression::new("var.enabled")),
Expand Down
7 changes: 7 additions & 0 deletions src/structure/expression.rs
Expand Up @@ -245,6 +245,7 @@ pub enum ObjectKey {

impl ObjectKey {
/// Creates an unquoted string identifier `ObjectKey`.
#[deprecated(since = "0.9.0", note = "use `ObjectKey::from(identifier)` instead")]
pub fn identifier<I>(identifier: I) -> Self
where
I: Into<Identifier>,
Expand All @@ -262,6 +263,12 @@ where
}
}

impl From<Identifier> for ObjectKey {
fn from(ident: Identifier) -> Self {
ObjectKey::Identifier(ident)
}
}

impl From<ObjectKey> for String {
fn from(key: ObjectKey) -> Self {
key.to_string()
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Expand Up @@ -42,7 +42,7 @@ fn expression_macro_objects() {
);

let expected = Expression::Object(Object::from([
(ObjectKey::identifier("foo"), "bar".into()),
(ObjectKey::from(Identifier::unchecked("foo")), "bar".into()),
(ObjectKey::from("bar"), true.into()),
(
ObjectKey::Expression(RawExpression::from("qux").into()),
Expand Down

0 comments on commit d2f5f94

Please sign in to comment.