Skip to content

Commit

Permalink
fix!: remove deprecated items (#355)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The deprecated `hcl::expr::RawExpression` type and the
`hcl::template::StripMode` alias were removed. Instead of the latter use
`hcl::template::Strip` instead. The former has not replacement.
  • Loading branch information
martinohmann authored May 24, 2024
1 parent e23f90c commit 8f32f31
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 157 deletions.
8 changes: 0 additions & 8 deletions crates/hcl-rs/src/eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ pub enum ErrorKind {
KeyExists(String),
/// A function call in an expression returned an error.
FuncCall(FuncName, String),
/// It was attempted to evaluate a raw expression.
#[deprecated(
since = "0.16.3",
note = "Support for raw expressions will be removed in an upcoming release"
)]
RawExpression,
}

impl From<Error> for ErrorKind {
Expand Down Expand Up @@ -264,8 +258,6 @@ impl fmt::Display for ErrorKind {
ErrorKind::FuncCall(name, msg) => {
write!(f, "error calling function `{name}`: {msg}")
}
#[allow(deprecated)]
ErrorKind::RawExpression => f.write_str("raw expressions cannot be evaluated"),
}
}
}
2 changes: 0 additions & 2 deletions crates/hcl-rs/src/eval/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ impl Evaluate for Expression {
Expression::Conditional(cond) => cond.evaluate(ctx),
Expression::Operation(op) => op.evaluate(ctx),
Expression::ForExpr(expr) => expr.evaluate(ctx),
#[allow(deprecated)]
Expression::Raw(_) => Err(ctx.error(ErrorKind::RawExpression)),
other => Ok(Value::from(other.clone())),
}
}
Expand Down
19 changes: 2 additions & 17 deletions crates/hcl-rs/src/expr/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl<'de> de::Deserialize<'de> for Expression {
Conditional,
Operation,
ForExpr,
Raw,
}

struct FieldVisitor;
Expand Down Expand Up @@ -82,10 +81,9 @@ impl<'de> de::Deserialize<'de> for Expression {
11u64 => Ok(Field::Conditional),
12u64 => Ok(Field::Operation),
13u64 => Ok(Field::ForExpr),
14u64 => Ok(Field::Raw),
_ => Err(de::Error::invalid_value(
Unexpected::Unsigned(value),
&"variant index 0 <= i < 15",
&"variant index 0 <= i < 14",
)),
}
}
Expand All @@ -109,7 +107,6 @@ impl<'de> de::Deserialize<'de> for Expression {
"Conditional" => Ok(Field::Conditional),
"Operation" => Ok(Field::Operation),
"ForExpr" => Ok(Field::ForExpr),
"Raw" => Ok(Field::Raw),
_ => Err(de::Error::unknown_variant(value, VARIANTS)),
}
}
Expand All @@ -133,7 +130,6 @@ impl<'de> de::Deserialize<'de> for Expression {
b"Conditional" => Ok(Field::Conditional),
b"Operation" => Ok(Field::Operation),
b"ForExpr" => Ok(Field::ForExpr),
b"Raw" => Ok(Field::Raw),
_ => {
let value = &String::from_utf8_lossy(value);
Err(de::Error::unknown_variant(value, VARIANTS))
Expand Down Expand Up @@ -248,7 +244,6 @@ impl<'de> de::Deserialize<'de> for Expression {
(Field::Conditional, v) => v.newtype_variant().map(Expression::Conditional),
(Field::Operation, v) => v.newtype_variant().map(Expression::Operation),
(Field::ForExpr, v) => v.newtype_variant().map(Expression::ForExpr),
(Field::Raw, v) => v.newtype_variant().map(Expression::Raw),
}
}
}
Expand All @@ -268,7 +263,6 @@ impl<'de> de::Deserialize<'de> for Expression {
"Conditional",
"Operation",
"ForExpr",
"Raw",
];

deserializer.deserialize_enum("$hcl::Expression", VARIANTS, ExpressionVisitor)
Expand Down Expand Up @@ -558,7 +552,6 @@ impl<'de> de::VariantAccess<'de> for Expression {
Expression::String(v) => seed.deserialize(v.into_deserializer()),
Expression::Array(v) => seed.deserialize(v.into_deserializer()),
Expression::Object(v) => seed.deserialize(v.into_deserializer()),
Expression::Raw(v) => seed.deserialize(v.into_deserializer()),
Expression::TemplateExpr(v) => seed.deserialize(*v),
Expression::Variable(v) => seed.deserialize(v.into_deserializer()),
Expression::Traversal(v) => seed.deserialize(v.into_deserializer()),
Expand Down Expand Up @@ -1166,14 +1159,6 @@ impl<'de> de::VariantAccess<'de> for ObjectKey {
}
}

impl<'de> IntoDeserializer<'de, Error> for RawExpression {
type Deserializer = StringDeserializer<Error>;

fn into_deserializer(self) -> Self::Deserializer {
self.into_inner().into_deserializer()
}
}

impl<'de> IntoDeserializer<'de, Error> for TemplateExpr {
type Deserializer = Self;

Expand Down Expand Up @@ -1281,7 +1266,7 @@ impl<'de> IntoDeserializer<'de, Error> for HeredocStripMode {

impl_variant_name! {
Expression => {
Null, Bool, Number, String, Array, Object, Raw, TemplateExpr, Variable,
Null, Bool, Number, String, Array, Object, TemplateExpr, Variable,
Traversal, FuncCall, Parenthesis, Conditional, Operation, ForExpr
},
ObjectKey => { Identifier, Expression },
Expand Down
3 changes: 0 additions & 3 deletions crates/hcl-rs/src/expr/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ impl From<Expression> for expr::Expression {
Expression::Traversal(traversal) => expr::Traversal::from(*traversal).into(),
Expression::Parenthesis(parens) => expr::Parenthesis::new((*parens).into()).into(),
Expression::Conditional(cond) => expr::Conditional::from(*cond).into(),
Expression::Raw(raw) => {
template::StringTemplate::from(template_or_default(raw.as_str())).into()
}
}
}
}
Expand Down
85 changes: 1 addition & 84 deletions crates/hcl-rs/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! The module contains the [`Expression`] enum which can represent any valid HCL expression in
//! HCL attribute values and templates.
#![allow(deprecated)]

mod conditional;
pub(crate) mod de;
mod edit;
Expand All @@ -31,7 +29,7 @@ use crate::ser::with_internal_serialization;
use crate::{Identifier, Number, Result, Value};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt::{self, Display, Write};
use std::fmt::{self, Display};

/// The object type used in the expression sub-language.
pub type Object<K, V> = vecmap::VecMap<K, V>;
Expand Down Expand Up @@ -71,13 +69,6 @@ pub enum Expression {
Operation(Box<Operation>),
/// A construct for constructing a collection by projecting the items from another collection.
ForExpr(Box<ForExpr>),
/// Represents a raw HCL expression. This variant will never be emitted by the parser. See
/// [`RawExpression`] for more details.
#[deprecated(
since = "0.16.3",
note = "Support for raw expressions will be removed in an upcoming release"
)]
Raw(RawExpression),
}

impl Expression {
Expand All @@ -101,7 +92,6 @@ impl From<Expression> for Value {
Expression::Object(object) => object.into_iter().collect(),
Expression::TemplateExpr(expr) => Value::String(expr.to_string()),
Expression::Parenthesis(expr) => Value::from(*expr),
Expression::Raw(raw) => Value::String(raw.into()),
other => Value::String(format::to_interpolated_string(&other).unwrap()),
}
}
Expand Down Expand Up @@ -217,12 +207,6 @@ impl From<()> for Expression {
}
}

impl From<RawExpression> for Expression {
fn from(raw: RawExpression) -> Self {
Expression::Raw(raw)
}
}

impl From<Traversal> for Expression {
fn from(traversal: Traversal) -> Self {
Expression::Traversal(Box::new(traversal))
Expand Down Expand Up @@ -344,73 +328,6 @@ impl Display for ObjectKey {
}
}

/// A type that holds the value of a raw expression. It can be used to serialize arbitrary
/// HCL expressions.
///
/// *Please note*: raw expressions are not validated during serialization, so it is your
/// responsiblity to ensure that they are valid HCL.
#[deprecated(
since = "0.16.3",
note = "Support for raw expressions will be removed in an upcoming release"
)]
#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
#[serde(transparent)]
pub struct RawExpression(String);

impl RawExpression {
/// Creates a new `RawExpression` from something that can be converted to a `String`.
pub fn new<E>(expr: E) -> RawExpression
where
E: Into<String>,
{
RawExpression(expr.into())
}

/// Consumes `self` and returns the `RawExpression` as a `String`. If you want to represent the
/// `RawExpression` as an interpolated string, use `.to_string()` instead.
pub fn into_inner(self) -> String {
self.0
}

/// Returns the `RawExpression` as a `&str`. If you want to represent the `RawExpression` as
/// an interpolated string, use `.to_string()` instead.
pub fn as_str(&self) -> &str {
&self.0
}
}

impl From<String> for RawExpression {
fn from(expr: String) -> Self {
RawExpression::new(expr)
}
}

impl From<&str> for RawExpression {
fn from(expr: &str) -> Self {
RawExpression::new(expr)
}
}

impl<'a> From<Cow<'a, str>> for RawExpression {
fn from(expr: Cow<'a, str>) -> Self {
RawExpression::new(expr)
}
}

impl From<RawExpression> for String {
fn from(expr: RawExpression) -> Self {
expr.to_string()
}
}

impl Display for RawExpression {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("${")?;
f.write_str(&self.0)?;
f.write_char('}')
}
}

/// Convert a `T` into `hcl::Expression` which is an enum that can represent any valid HCL
/// attribute value expression.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/hcl-rs/src/expr/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! impl_serialize_for_expr {

impl_serialize_for_expr! {
Conditional ForExpr FuncCall Operation UnaryOp BinaryOp
TemplateExpr Heredoc RawExpression Traversal Variable
TemplateExpr Heredoc Traversal Variable
}

impl ser::Serialize for HeredocStripMode {
Expand Down Expand Up @@ -72,7 +72,6 @@ impl ser::Serialize for Expression {
Expression::Conditional(cond) => cond.serialize(serializer),
Expression::Operation(op) => op.serialize(serializer),
Expression::ForExpr(expr) => expr.serialize(serializer),
Expression::Raw(raw) => raw.serialize(serializer),
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions crates/hcl-rs/src/format/impls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::{private, Format, Formatter};
#[allow(deprecated)]
use crate::expr::RawExpression;
use crate::expr::{
BinaryOp, Conditional, Expression, ForExpr, FuncCall, FuncName, Heredoc, HeredocStripMode,
ObjectKey, Operation, TemplateExpr, Traversal, TraversalOperator, UnaryOp, Variable,
Expand Down Expand Up @@ -122,8 +120,6 @@ impl Format for Expression {
Expression::String(string) => string.format(fmt),
Expression::Array(array) => format_array(fmt, array.iter()),
Expression::Object(object) => format_object(fmt, object.iter()),
#[allow(deprecated)]
Expression::Raw(raw) => raw.format(fmt),
Expression::TemplateExpr(expr) => expr.format(fmt),
Expression::Variable(var) => var.format(fmt),
Expression::Traversal(traversal) => traversal.format(fmt),
Expand Down Expand Up @@ -207,19 +203,6 @@ impl<'a> Format for StrKey<'a> {
}
}

#[allow(deprecated)]
impl private::Sealed for RawExpression {}

#[allow(deprecated)]
impl Format for RawExpression {
fn format<W>(&self, fmt: &mut Formatter<W>) -> Result<()>
where
W: io::Write,
{
fmt.write_bytes(self.as_str().as_bytes())
}
}

impl private::Sealed for TemplateExpr {}

impl Format for TemplateExpr {
Expand Down
4 changes: 0 additions & 4 deletions crates/hcl-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ pub use expr::{
UnaryOperator, Variable,
};

#[allow(deprecated)]
#[doc(hidden)]
pub use expr::RawExpression;

pub use ident::Identifier;
pub use parser::parse;

Expand Down
13 changes: 0 additions & 13 deletions crates/hcl-rs/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ macro_rules! object_key {
$crate::expr::ObjectKey::Identifier($crate::Identifier::unchecked(std::stringify!($ident)))
};

(#{$expr:expr}) => {
$crate::expr::ObjectKey::Expression($crate::expression!(#{$expr}))
};

(($expr:expr)) => {
$crate::expr::ObjectKey::Expression($crate::expression!($expr))
};
Expand Down Expand Up @@ -586,11 +582,6 @@ macro_rules! expression_internal {
$crate::expression_internal!(@object $object ($crate::object_key!($key)) ($($rest)*) ($($rest)*));
};

// Munch a raw expression key.
(@object $object:ident () (#{$key:expr} $($rest:tt)*) $copy:tt) => {
$crate::expression_internal!(@object $object ($crate::object_key!(#{$key})) ($($rest)*) ($($rest)*));
};

// Munch a parenthesized expression key.
(@object $object:ident () (($key:expr) $($rest:tt)*) $copy:tt) => {
$crate::expression_internal!(@object $object ($crate::object_key!(($key))) ($($rest)*) ($($rest)*));
Expand All @@ -614,10 +605,6 @@ macro_rules! expression_internal {
$crate::expr::Expression::Bool(false)
};

(#{$expr:expr}) => {
$crate::expr::Expression::Raw(($expr).into())
};

([]) => {
$crate::expr::Expression::Array(std::vec![])
};
Expand Down
10 changes: 3 additions & 7 deletions crates/hcl-rs/src/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//! # fn main() -> Result<(), Box<dyn Error>> {
//! use hcl::Identifier;
//! use hcl::expr::Variable;
//! use hcl::template::{ForDirective, StripMode, Template};
//! use hcl::template::{ForDirective, Strip, Template};
//! use std::str::FromStr;
//!
//! let raw = r#"
Expand All @@ -67,8 +67,8 @@
//! .add_interpolation(Variable::new("item")?)
//! .add_literal("\n")
//! )
//! .with_for_strip(StripMode::End)
//! .with_endfor_strip(StripMode::End)
//! .with_for_strip(Strip::End)
//! .with_endfor_strip(Strip::End)
//! )
//! .add_literal("\n");
//!
Expand All @@ -95,10 +95,6 @@ use std::str::FromStr;
#[doc(inline)]
pub use hcl_primitives::template::Strip;

#[doc(hidden)]
#[deprecated(since = "0.14.0", note = "use `hcl::template::Strip` instead")]
pub type StripMode = Strip;

/// The main type to represent the HCL template sub-languange.
///
/// A template behaves like an expression that always returns a string value. The different
Expand Down

0 comments on commit 8f32f31

Please sign in to comment.