Merge pull request #897 from SorenHolstHansen/cursor-types

Added impl of CursorType for floats
This commit is contained in:
Sunli 2022-04-28 12:01:06 +08:00 committed by GitHub
commit f7d292a1dc
1 changed files with 27 additions and 1 deletions

View File

@ -1,4 +1,6 @@
use std::{convert::Infallible, fmt::Display, num::ParseIntError};
use std::convert::Infallible;
use std::fmt::Display;
use std::num::{ParseFloatError, ParseIntError};
use crate::ID;
@ -76,3 +78,27 @@ impl CursorType for ID {
self.to_string()
}
}
impl CursorType for f64 {
type Error = ParseFloatError;
fn decode_cursor(s: &str) -> Result<Self, Self::Error> {
s.parse()
}
fn encode_cursor(&self) -> String {
self.to_string()
}
}
impl CursorType for f32 {
type Error = ParseFloatError;
fn decode_cursor(s: &str) -> Result<Self, Self::Error> {
s.parse()
}
fn encode_cursor(&self) -> String {
self.to_string()
}
}