Replace a bunch of Into impls with Froms

This commit is contained in:
Richard Feldman 2021-03-26 08:39:01 -04:00
parent 7d004c48b1
commit eadb28b95d
6 changed files with 51 additions and 51 deletions

View File

@ -90,9 +90,9 @@ pub enum OptLevel {
Optimize,
}
impl Into<OptimizationLevel> for OptLevel {
fn into(self) -> OptimizationLevel {
match self {
impl From<OptLevel> for OptimizationLevel {
fn from(level: OptLevel) -> Self {
match level {
OptLevel::Normal => OptimizationLevel::None,
OptLevel::Optimize => OptimizationLevel::Aggressive,
}

View File

@ -8,9 +8,9 @@ pub enum RocCallResult<T> {
Failure(*mut c_char),
}
impl<T: Sized> Into<Result<T, String>> for RocCallResult<T> {
fn into(self) -> Result<T, String> {
match self {
impl<T: Sized> From<RocCallResult<T>> for Result<T, String> {
fn from(call_result: RocCallResult<T>) -> Self {
match call_result {
Success(value) => Ok(value),
Failure(failure) => Err({
let raw = unsafe { CString::from_raw(failure) };

View File

@ -117,21 +117,21 @@ impl From<InlinableString> for ModuleName {
}
}
impl Into<InlinableString> for ModuleName {
fn into(self) -> InlinableString {
self.0
impl From<ModuleName> for InlinableString {
fn from(name: ModuleName) -> Self {
name.0
}
}
impl<'a> Into<&'a InlinableString> for &'a ModuleName {
fn into(self) -> &'a InlinableString {
&self.0
impl<'a> From<&'a ModuleName> for &'a InlinableString {
fn from(name: &'a ModuleName) -> Self {
&name.0
}
}
impl<'a> Into<Box<str>> for ModuleName {
fn into(self) -> Box<str> {
self.0.to_string().into()
impl From<ModuleName> for Box<str> {
fn from(name: ModuleName) -> Self {
name.0.to_string().into()
}
}
@ -197,9 +197,9 @@ impl<'a> From<String> for Lowercase {
}
}
impl Into<InlinableString> for Lowercase {
fn into(self) -> InlinableString {
self.0
impl From<Lowercase> for InlinableString {
fn from(lowercase: Lowercase) -> Self {
lowercase.0
}
}
@ -234,21 +234,21 @@ impl From<InlinableString> for Ident {
}
}
impl Into<InlinableString> for Ident {
fn into(self) -> InlinableString {
self.0
impl From<Ident> for InlinableString {
fn from(ident: Ident) -> Self {
ident.0
}
}
impl<'a> Into<&'a InlinableString> for &'a Ident {
fn into(self) -> &'a InlinableString {
&self.0
impl<'a> From<&'a Ident> for &'a InlinableString {
fn from(ident: &'a Ident) -> Self {
&ident.0
}
}
impl<'a> Into<Box<str>> for Ident {
fn into(self) -> Box<str> {
self.0.to_string().into()
impl From<Ident> for Box<str> {
fn from(ident: Ident) -> Self {
ident.0.to_string().into()
}
}

View File

@ -42,15 +42,15 @@ pub enum PackageOrPath<'a> {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct ModuleName<'a>(&'a str);
impl<'a> Into<&'a str> for ModuleName<'a> {
fn into(self) -> &'a str {
self.0
impl<'a> From<ModuleName<'a>> for &'a str {
fn from(name: ModuleName<'a>) -> Self {
name.0
}
}
impl<'a> Into<InlinableString> for ModuleName<'a> {
fn into(self) -> InlinableString {
self.0.into()
impl<'a> From<ModuleName<'a>> for InlinableString {
fn from(name: ModuleName<'a>) -> InlinableString {
name.0.into()
}
}

View File

@ -93,9 +93,9 @@ impl VarStore {
}
}
impl Into<Variable> for VarStore {
fn into(self) -> Variable {
Variable(self.next)
impl From<VarStore> for Variable {
fn from(store: VarStore) -> Self {
Variable(store.next)
}
}
@ -139,9 +139,9 @@ impl fmt::Debug for OptVariable {
}
}
impl Into<Option<Variable>> for OptVariable {
fn into(self) -> Option<Variable> {
self.into_variable()
impl From<OptVariable> for Option<Variable> {
fn from(opt_var: OptVariable) -> Self {
opt_var.into_variable()
}
}
@ -180,9 +180,9 @@ impl Variable {
}
}
impl Into<OptVariable> for Variable {
fn into(self) -> OptVariable {
OptVariable(self.0)
impl From<Variable> for OptVariable {
fn from(var: Variable) -> Self {
OptVariable(var.0)
}
}
@ -483,9 +483,9 @@ impl fmt::Debug for Rank {
}
}
impl Into<usize> for Rank {
fn into(self) -> usize {
self.0
impl From<Rank> for usize {
fn from(rank: Rank) -> Self {
rank.0
}
}

View File

@ -502,11 +502,11 @@ pub enum RocCallResult<T> {
Failure(*mut c_char),
}
impl<T: Sized> Into<Result<T, &'static str>> for RocCallResult<T> {
fn into(self) -> Result<T, &'static str> {
impl<T: Sized> From<RocCallResult<T>> for Result<T, &'static str> {
fn from(call_result: RocCallResult<T>) -> Self {
use RocCallResult::*;
match self {
match call_result {
Success(value) => Ok(value),
Failure(failure) => Err({
let msg = unsafe {
@ -529,11 +529,11 @@ impl<T: Sized> Into<Result<T, &'static str>> for RocCallResult<T> {
}
}
impl<'a, T: Sized + Copy> Into<Result<T, &'a str>> for &'a RocCallResult<T> {
fn into(self) -> Result<T, &'a str> {
impl<'a, T: Sized + Copy> From<&'a RocCallResult<T>> for Result<T, &'a str> {
fn from(call_result: &'a RocCallResult<T>) -> Self {
use RocCallResult::*;
match self {
match call_result {
Success(value) => Ok(*value),
Failure(failure) => Err({
let msg = unsafe {