Skip to content

Commit

Permalink
chore: mark BlockLabel::{string,identifier} functions as deprecated
Browse files Browse the repository at this point in the history
They will be removed entirely as part of the future minor or major
release.
  • Loading branch information
martinohmann committed Oct 27, 2022
1 parent 5e1501a commit 86dda75
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
11 changes: 7 additions & 4 deletions src/macros.rs
Expand Up @@ -355,14 +355,17 @@ macro_rules! block_internal {
/// ## Examples
///
/// ```
/// use hcl::BlockLabel;
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use hcl::{BlockLabel, Identifier};
///
/// assert_eq!(hcl::block_label!(some_identifier), BlockLabel::identifier("some_identifier"));
/// assert_eq!(hcl::block_label!("some string"), BlockLabel::string("some string"));
/// assert_eq!(hcl::block_label!(some_identifier), BlockLabel::from(Identifier::new("some_identifier")?));
/// assert_eq!(hcl::block_label!("some string"), BlockLabel::from("some string"));
///
/// let label = "some expression";
///
/// assert_eq!(hcl::block_label!((label)), BlockLabel::string("some expression"));
/// assert_eq!(hcl::block_label!((label)), BlockLabel::from("some expression"));
/// # Ok(())
/// # }
/// ```
#[macro_export]
macro_rules! block_label {
Expand Down
6 changes: 3 additions & 3 deletions src/ser/tests.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::{
Attribute, BinaryOp, BinaryOperator, Block, BlockLabel, Body, Conditional, Expression, ForExpr,
FuncCall, Heredoc, HeredocStripMode, Identifier, Object, ObjectKey, Operation, RawExpression,
Attribute, BinaryOp, BinaryOperator, Block, Body, Conditional, Expression, ForExpr, FuncCall,
Heredoc, HeredocStripMode, Identifier, Object, ObjectKey, Operation, RawExpression,
TemplateExpr, Traversal, TraversalOperator, Variable,
};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -80,7 +80,7 @@ fn serialize_body() {
.add_attribute(("foo", "bar"))
.add_block(
Block::builder("with_labels")
.add_label(BlockLabel::identifier("label1"))
.add_label(Identifier::unchecked("label1"))
.add_label("lab\"el2")
.add_attribute(("baz", vec![1u64, 2u64, 3u64]))
.build(),
Expand Down
12 changes: 10 additions & 2 deletions src/structure/block.rs
Expand Up @@ -114,6 +114,7 @@ pub enum BlockLabel {

impl BlockLabel {
/// Creates a new bare `BlockLabel` identifier.
#[deprecated(since = "0.9.0", note = "use `BlockLabel::from(identifier)` instead")]
pub fn identifier<I>(identifier: I) -> Self
where
I: Into<Identifier>,
Expand All @@ -122,6 +123,7 @@ impl BlockLabel {
}

/// Creates a new quoted string `BlockLabel`.
#[deprecated(since = "0.9.0", note = "use `BlockLabel::from(string)` instead")]
pub fn string<S>(string: S) -> Self
where
S: Into<String>,
Expand All @@ -145,8 +147,14 @@ impl<T> From<T> for BlockLabel
where
T: Into<String>,
{
fn from(v: T) -> BlockLabel {
BlockLabel::string(v)
fn from(s: T) -> BlockLabel {
BlockLabel::String(s.into())
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/structure/mod.rs
Expand Up @@ -42,7 +42,7 @@
//! assert_eq!(block.identifier(), "resource");
//! assert_eq!(
//! block.labels().first(),
//! Some(&BlockLabel::string("aws_s3_bucket")),
//! Some(&BlockLabel::from("aws_s3_bucket")),
//! );
//! ```

Expand Down
12 changes: 6 additions & 6 deletions src/structure/ser/tests.rs
Expand Up @@ -53,19 +53,19 @@ fn identity() {
.add_attribute(("baz", "qux"))
.build(),
);
test_identity(BlockLabelSerializer, BlockLabel::string("foo"));
test_identity(BlockLabelSerializer, BlockLabel::identifier("foo"));
test_identity(BlockLabelSerializer, BlockLabel::from("foo"));
test_identity(
BlockLabelSerializer,
BlockLabel::from(Identifier::unchecked("foo")),
);
test_identity(ExpressionSerializer, Expression::Null);
test_identity(ExpressionSerializer, Expression::Number(1.into()));
test_identity(ExpressionSerializer, Expression::String("bar".into()));
test_identity(
ExpressionSerializer,
Expression::from_iter([("foo", "bar")]),
);
test_identity(
TemplateExprSerializer,
TemplateExpr::QuotedString("${foo}".into()),
);
test_identity(TemplateExprSerializer, TemplateExpr::from("${foo}"));
test_identity(
TemplateExprSerializer,
TemplateExpr::Heredoc(
Expand Down
12 changes: 6 additions & 6 deletions src/tests.rs
Expand Up @@ -83,16 +83,16 @@ fn block_macro() {
assert_eq!(
block!(resource "aws_s3_bucket" "bucket" {}),
Block::builder("resource")
.add_label(BlockLabel::string("aws_s3_bucket"))
.add_label(BlockLabel::string("bucket"))
.add_label("aws_s3_bucket")
.add_label("bucket")
.build()
);

assert_eq!(
block!(resource aws_s3_bucket bucket {}),
Block::builder("resource")
.add_label(BlockLabel::identifier("aws_s3_bucket"))
.add_label(BlockLabel::identifier("bucket"))
.add_label(Identifier::unchecked("aws_s3_bucket"))
.add_label(Identifier::unchecked("bucket"))
.build()
);

Expand All @@ -102,8 +102,8 @@ fn block_macro() {
assert_eq!(
block!((ident) aws_s3_bucket (name) {}),
Block::builder("resource")
.add_label(BlockLabel::identifier("aws_s3_bucket"))
.add_label(BlockLabel::string("bucket"))
.add_label(Identifier::unchecked("aws_s3_bucket"))
.add_label("bucket")
.build()
);
}
Expand Down

0 comments on commit 86dda75

Please sign in to comment.