mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge pull request #238 from Foundation-Devices/from-into
Implement From instead of Into.
This commit is contained in:
commit
be239f9812
16 changed files with 84 additions and 85 deletions
|
|
@ -18,7 +18,6 @@ use super::status_code::Ctap2StatusCode;
|
||||||
use super::CtapState;
|
use super::CtapState;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use arrayref::array_ref;
|
use arrayref::array_ref;
|
||||||
use core::convert::Into;
|
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
use ctap_crypto::rng256::Rng256;
|
use ctap_crypto::rng256::Rng256;
|
||||||
use crate::shims::ClockValue;
|
use crate::shims::ClockValue;
|
||||||
|
|
@ -51,9 +50,9 @@ impl TryFrom<u8> for Ctap1Flags {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<u8> for Ctap1Flags {
|
impl From<Ctap1Flags> for u8 {
|
||||||
fn into(self) -> u8 {
|
fn from(flags: Ctap1Flags) -> u8 {
|
||||||
self as u8
|
flags as u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,12 @@ impl From<[usize; 2]> for BattStats {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 2]> for BattStats {
|
impl From<BattStats> for [usize; 2]{
|
||||||
fn into(self) -> [usize; 2] {
|
fn from(stats: BattStats) -> [usize; 2] {
|
||||||
[
|
[
|
||||||
(self.voltage as usize & 0xffff) | ((self.soc as usize) << 16) & 0xFF_0000,
|
(stats.voltage as usize & 0xffff) | ((stats.soc as usize) << 16) & 0xFF_0000,
|
||||||
(self.remaining_capacity as usize & 0xffff)
|
(stats.remaining_capacity as usize & 0xffff)
|
||||||
| ((self.current as usize) << 16) & 0xffff_0000,
|
| ((stats.current as usize) << 16) & 0xffff_0000,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ impl core::convert::TryFrom<&Message> for Opcode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Message> for Opcode {
|
impl From<Opcode> for Message {
|
||||||
fn into(self) -> Message {
|
fn from(opcode: Opcode) -> Message {
|
||||||
match self {
|
match opcode {
|
||||||
Opcode::Redraw => Message::Scalar(ScalarMessage {
|
Opcode::Redraw => Message::Scalar(ScalarMessage {
|
||||||
id: 0,
|
id: 0,
|
||||||
arg1: 0,
|
arg1: 0,
|
||||||
|
|
@ -31,7 +31,7 @@ impl Into<Message> for Opcode {
|
||||||
arg3: 0,
|
arg3: 0,
|
||||||
arg4: 0,
|
arg4: 0,
|
||||||
}),
|
}),
|
||||||
// _ => panic!("SHCH api: Opcode type not handled by Into(), refer to helper method"),
|
// _ => panic!("SHCH api: Opcode type not handled by From<Opcode>, refer to helper method"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ impl From<usize> for GlyphStyle {
|
||||||
|
|
||||||
/// Convert style to number for use with register-based message passing sytems
|
/// Convert style to number for use with register-based message passing sytems
|
||||||
// [by bunnie for Xous]
|
// [by bunnie for Xous]
|
||||||
impl Into<usize> for GlyphStyle {
|
impl From<GlyphStyle> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(g: GlyphStyle) -> usize {
|
||||||
match self {
|
match g {
|
||||||
GlyphStyle::Small => 0,
|
GlyphStyle::Small => 0,
|
||||||
GlyphStyle::Regular => 1,
|
GlyphStyle::Regular => 1,
|
||||||
GlyphStyle::Bold => 2,
|
GlyphStyle::Bold => 2,
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,9 @@ impl From<&Point> for (i16, i16) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<usize> for Point {
|
impl From<Point> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(point: Point) -> usize {
|
||||||
(self.x as usize) << 16 | (self.y as usize)
|
(point.x as usize) << 16 | (point.y as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -248,13 +248,13 @@ impl Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<ClipRect> for Rectangle {
|
impl From<Rectangle> for ClipRect {
|
||||||
fn into(self) -> ClipRect {
|
fn from(rectangle: Rectangle) -> ClipRect {
|
||||||
ClipRect::new(
|
ClipRect::new(
|
||||||
self.x0() as _,
|
rectangle.x0() as _,
|
||||||
self.y0() as _,
|
rectangle.y0() as _,
|
||||||
self.x1() as _,
|
rectangle.x1() as _,
|
||||||
self.y1() as _,
|
rectangle.y1() as _,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ impl From<bool> for PixelColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<bool> for PixelColor {
|
impl From<PixelColor> for bool {
|
||||||
fn into(self) -> bool {
|
fn from(pc: PixelColor) -> bool {
|
||||||
if self == PixelColor::Dark {
|
if pc == PixelColor::Dark {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
@ -36,9 +36,9 @@ impl From<usize> for PixelColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<usize> for PixelColor {
|
impl From<PixelColor> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(pc: PixelColor) -> usize {
|
||||||
if self == PixelColor::Light {
|
if pc == PixelColor::Light {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
|
|
@ -103,11 +103,11 @@ impl From<usize> for DrawStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<usize> for DrawStyle {
|
impl From<DrawStyle> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(draw_style: DrawStyle) -> usize {
|
||||||
let sc: usize;
|
let sc: usize;
|
||||||
if self.stroke_color.is_some() {
|
if draw_style.stroke_color.is_some() {
|
||||||
if self.stroke_color.unwrap() == PixelColor::Dark {
|
if draw_style.stroke_color.unwrap() == PixelColor::Dark {
|
||||||
sc = 0b11;
|
sc = 0b11;
|
||||||
} else {
|
} else {
|
||||||
sc = 0b10;
|
sc = 0b10;
|
||||||
|
|
@ -116,8 +116,8 @@ impl Into<usize> for DrawStyle {
|
||||||
sc = 0;
|
sc = 0;
|
||||||
}
|
}
|
||||||
let fc: usize;
|
let fc: usize;
|
||||||
if self.fill_color.is_some() {
|
if draw_style.fill_color.is_some() {
|
||||||
if self.fill_color.unwrap() == PixelColor::Dark {
|
if draw_style.fill_color.unwrap() == PixelColor::Dark {
|
||||||
fc = 0b11;
|
fc = 0b11;
|
||||||
} else {
|
} else {
|
||||||
fc = 0b10;
|
fc = 0b10;
|
||||||
|
|
@ -126,7 +126,7 @@ impl Into<usize> for DrawStyle {
|
||||||
} else {
|
} else {
|
||||||
fc = 0;
|
fc = 0;
|
||||||
}
|
}
|
||||||
(self.stroke_width as usize) << 16 | sc << 2 | fc
|
(draw_style.stroke_width as usize) << 16 | sc << 2 | fc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@ pub enum TextOp {
|
||||||
Render,
|
Render,
|
||||||
ComputeBounds, // maybe we don't need this
|
ComputeBounds, // maybe we don't need this
|
||||||
}
|
}
|
||||||
impl Into<usize> for TextOp {
|
impl From<TextOp> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(op: TextOp) -> usize {
|
||||||
match self {
|
match op {
|
||||||
TextOp::Nop => 0,
|
TextOp::Nop => 0,
|
||||||
TextOp::Render => 1,
|
TextOp::Render => 1,
|
||||||
TextOp::ComputeBounds => 2,
|
TextOp::ComputeBounds => 2,
|
||||||
|
|
|
||||||
|
|
@ -34,16 +34,16 @@ pub struct PredictionTriggers {
|
||||||
/// trigger word predictions on whitespace
|
/// trigger word predictions on whitespace
|
||||||
pub whitespace: bool,
|
pub whitespace: bool,
|
||||||
}
|
}
|
||||||
impl Into<usize> for PredictionTriggers {
|
impl From<PredictionTriggers> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(pt: PredictionTriggers) -> usize {
|
||||||
let mut ret: usize = 0;
|
let mut ret: usize = 0;
|
||||||
if self.newline {
|
if pt.newline {
|
||||||
ret |= 0x1;
|
ret |= 0x1;
|
||||||
}
|
}
|
||||||
if self.punctuation {
|
if pt.punctuation {
|
||||||
ret |= 0x2;
|
ret |= 0x2;
|
||||||
}
|
}
|
||||||
if self.whitespace {
|
if pt.whitespace {
|
||||||
ret |= 0x4;
|
ret |= 0x4;
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,9 @@ impl From<usize> for KeyMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Into<usize> for KeyMap {
|
impl From<KeyMap> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(map: KeyMap) -> usize {
|
||||||
match self {
|
match map {
|
||||||
// note: these indicese correspond to the position on the keyboard menu
|
// note: these indicese correspond to the position on the keyboard menu
|
||||||
KeyMap::Qwerty => 0,
|
KeyMap::Qwerty => 0,
|
||||||
KeyMap::Azerty => 1,
|
KeyMap::Azerty => 1,
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ impl From<usize> for UartType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Into<usize> for UartType {
|
impl From<UartType> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(uart_type: UartType) -> usize {
|
||||||
match self {
|
match uart_type {
|
||||||
UartType::Kernel => 0,
|
UartType::Kernel => 0,
|
||||||
UartType::Log => 1,
|
UartType::Log => 1,
|
||||||
UartType::Application => 2,
|
UartType::Application => 2,
|
||||||
|
|
@ -38,9 +38,9 @@ impl Into<usize> for UartType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for the actual bitmask going to hardware
|
// for the actual bitmask going to hardware
|
||||||
impl Into<u32> for UartType {
|
impl From<UartType> for u32 {
|
||||||
fn into(self) -> u32 {
|
fn from(uart_type: UartType) -> u32 {
|
||||||
match self {
|
match uart_type {
|
||||||
UartType::Kernel => 0,
|
UartType::Kernel => 0,
|
||||||
UartType::Log => 1,
|
UartType::Log => 1,
|
||||||
UartType::Application => 2,
|
UartType::Application => 2,
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ impl From<usize> for VibePattern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Into<usize> for VibePattern {
|
impl From<VibePattern> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(pat: VibePattern) -> usize {
|
||||||
match self {
|
match pat {
|
||||||
VibePattern::Long => 0,
|
VibePattern::Long => 0,
|
||||||
VibePattern::Double => 1,
|
VibePattern::Double => 1,
|
||||||
VibePattern::Short => 0xffff_ffff,
|
VibePattern::Short => 0xffff_ffff,
|
||||||
|
|
@ -39,9 +39,9 @@ impl From<usize> for ClockMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Into<usize> for ClockMode {
|
impl From<ClockMode> for usize {
|
||||||
fn into(self) -> usize {
|
fn from(mode: ClockMode) -> usize {
|
||||||
match self {
|
match mode {
|
||||||
ClockMode::Low => 0,
|
ClockMode::Low => 0,
|
||||||
ClockMode::AllOn => 0xffff_ffff,
|
ClockMode::AllOn => 0xffff_ffff,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -315,9 +315,9 @@ impl From::<KeyMap> for BackupKeyboardLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Into::<KeyMap> for BackupKeyboardLayout {
|
impl From<BackupKeyboardLayout> for KeyMap {
|
||||||
fn into(self) -> KeyMap {
|
fn from(layout: BackupKeyboardLayout) -> KeyMap {
|
||||||
match self {
|
match layout {
|
||||||
BackupKeyboardLayout::Qwerty => KeyMap::Qwerty,
|
BackupKeyboardLayout::Qwerty => KeyMap::Qwerty,
|
||||||
BackupKeyboardLayout::Braille => KeyMap::Braille,
|
BackupKeyboardLayout::Braille => KeyMap::Braille,
|
||||||
BackupKeyboardLayout::Dvorak => KeyMap::Dvorak,
|
BackupKeyboardLayout::Dvorak => KeyMap::Dvorak,
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,13 @@ impl ProcessArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessInit {
|
impl From<&ProcessInit> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn from(init: &ProcessInit) -> [usize; 7] {
|
||||||
[
|
[
|
||||||
u32::from_le_bytes(self.key.0[0..4].try_into().unwrap()) as _,
|
u32::from_le_bytes(init.key.0[0..4].try_into().unwrap()) as _,
|
||||||
u32::from_le_bytes(self.key.0[4..8].try_into().unwrap()) as _,
|
u32::from_le_bytes(init.key.0[4..8].try_into().unwrap()) as _,
|
||||||
u32::from_le_bytes(self.key.0[8..12].try_into().unwrap()) as _,
|
u32::from_le_bytes(init.key.0[8..12].try_into().unwrap()) as _,
|
||||||
u32::from_le_bytes(self.key.0[12..16].try_into().unwrap()) as _,
|
u32::from_le_bytes(init.key.0[12..16].try_into().unwrap()) as _,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
@ -120,9 +120,9 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessStartup {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn from(startup: &ProcessStartup) -> [usize; 7] {
|
||||||
[self.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
[startup.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ pub struct ProcessInit {
|
||||||
// 6
|
// 6
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessInit {
|
impl From<&ProcessInit> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn into(self) -> [usize; 7] {
|
||||||
[
|
[
|
||||||
self.stack.addr.get(),
|
self.stack.addr.get(),
|
||||||
|
|
@ -121,7 +121,7 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessStartup {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn into(self) -> [usize; 7] {
|
||||||
[self.pid.get() as _, self.connection as _, 0, 0, 0, 0, 0]
|
[self.pid.get() as _, self.connection as _, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,13 @@ impl ProcessKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<String> for ProcessKey {
|
impl core::fmt::Display for ProcessKey {
|
||||||
fn into(self) -> String {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
let mut out = String::new();
|
|
||||||
for i in self.0 {
|
for i in self.0 {
|
||||||
out.push_str(&format!("{:02x}", i));
|
write!(f, "{:02x}", i)?;
|
||||||
}
|
}
|
||||||
out
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,14 +184,14 @@ impl From<[usize; 8]> for ProcessStartup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessStartup {
|
impl From<&ProcessStartup> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn from(startup: &ProcessStartup) -> [usize; 7] {
|
||||||
[self.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
[startup.pid.get() as _, 0, 0, 0, 0, 0, 0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<[usize; 7]> for &ProcessInit {
|
impl From<&ProcessInit> for [usize; 7] {
|
||||||
fn into(self) -> [usize; 7] {
|
fn from(init: &ProcessInit) -> [usize; 7] {
|
||||||
[
|
[
|
||||||
u32::from_le_bytes(self.key.0[0..4].try_into().unwrap()) as _,
|
u32::from_le_bytes(self.key.0[0..4].try_into().unwrap()) as _,
|
||||||
u32::from_le_bytes(self.key.0[4..8].try_into().unwrap()) as _,
|
u32::from_le_bytes(self.key.0[4..8].try_into().unwrap()) as _,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue