Reduce unnecessary generics.

This commit is contained in:
Stephen Chung
2022-10-20 15:31:57 +08:00
parent f8888c83e7
commit c24794187f
8 changed files with 88 additions and 30 deletions

View File

@@ -5,6 +5,7 @@ use crate::{Dynamic, FnNamespace, Identifier, Position};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
borrow::Borrow,
fmt,
hash::Hash,
ops::{Add, AddAssign},
@@ -919,6 +920,14 @@ impl<A: Into<Self>> AddAssign<A> for AST {
}
}
impl Borrow<[Stmt]> for AST {
#[inline(always)]
#[must_use]
fn borrow(&self) -> &[Stmt] {
self.statements()
}
}
impl AsRef<[Stmt]> for AST {
#[inline(always)]
#[must_use]
@@ -927,6 +936,15 @@ impl AsRef<[Stmt]> for AST {
}
}
#[cfg(not(feature = "no_function"))]
impl Borrow<crate::Module> for AST {
#[inline(always)]
#[must_use]
fn borrow(&self) -> &crate::Module {
&self.shared_lib()
}
}
#[cfg(not(feature = "no_function"))]
impl AsRef<crate::Module> for AST {
#[inline(always)]
@@ -936,6 +954,15 @@ impl AsRef<crate::Module> for AST {
}
}
#[cfg(not(feature = "no_function"))]
impl Borrow<crate::Shared<crate::Module>> for AST {
#[inline(always)]
#[must_use]
fn borrow(&self) -> &crate::Shared<crate::Module> {
self.shared_lib()
}
}
#[cfg(not(feature = "no_function"))]
impl AsRef<crate::Shared<crate::Module>> for AST {
#[inline(always)]

View File

@@ -4,6 +4,7 @@ use crate::{ImmutableString, Position};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
borrow::Borrow,
fmt,
hash::Hash,
ops::{Deref, DerefMut},
@@ -28,6 +29,14 @@ impl fmt::Debug for Ident {
}
}
impl Borrow<str> for Ident {
#[inline(always)]
#[must_use]
fn borrow(&self) -> &str {
self.name.as_ref()
}
}
impl AsRef<str> for Ident {
#[inline(always)]
#[must_use]

View File

@@ -7,6 +7,7 @@ use crate::{calc_fn_hash, Position, StaticVec, INT};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
borrow::Borrow,
collections::BTreeMap,
fmt,
hash::Hash,
@@ -443,6 +444,14 @@ impl DerefMut for StmtBlock {
}
}
impl Borrow<[Stmt]> for StmtBlock {
#[inline(always)]
#[must_use]
fn borrow(&self) -> &[Stmt] {
&self.block
}
}
impl AsRef<[Stmt]> for StmtBlock {
#[inline(always)]
#[must_use]