Deprecate Position::new_const.

This commit is contained in:
Stephen Chung 2022-02-24 09:08:10 +08:00
parent 7263896776
commit 2f5ce2fe5b
2 changed files with 26 additions and 22 deletions

View File

@ -2,7 +2,7 @@
use crate::{
Dynamic, Engine, EvalAltResult, Expression, FnPtr, ImmutableString, NativeCallContext,
RhaiResult, RhaiResultOf, Scope, AST,
Position, RhaiResult, RhaiResultOf, Scope, AST,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@ -314,3 +314,27 @@ impl Expression<'_> {
self.get_string_value()
}
}
impl Position {
/// Create a new [`Position`].
///
/// If `line` is zero, then [`None`] is returned.
///
/// If `position` is zero, then it is at the beginning of a line.
///
/// # Deprecated
///
/// This function is deprecated. Use [`new`][Position::new] (which panics when `line` is zero) instead.
///
/// This method will be removed in the next major version.
#[deprecated(since = "1.6.0", note = "use `new` instead")]
#[inline(always)]
#[must_use]
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
if line == 0 {
None
} else {
Some(Self::new(line, position))
}
}
}

View File

@ -94,7 +94,7 @@ impl Position {
/// Panics if `line` is zero.
#[inline(always)]
#[must_use]
pub fn new(line: u16, position: u16) -> Self {
pub const fn new(line: u16, position: u16) -> Self {
assert!(line != 0, "line cannot be zero");
let _pos = position;
@ -106,26 +106,6 @@ impl Position {
pos: _pos,
}
}
/// Create a new [`Position`].
///
/// If `line` is zero, then [`None`] is returned.
///
/// If `position` is zero, then it is at the beginning of a line.
#[inline]
#[must_use]
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
if line == 0 {
return None;
}
let _pos = position;
Some(Self {
#[cfg(not(feature = "no_position"))]
line,
#[cfg(not(feature = "no_position"))]
pos: _pos,
})
}
/// Get the line number (1-based), or [`None`] if there is no position.
#[inline]
#[must_use]