-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support overriding the type name of a column
- Loading branch information
Showing
16 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use self::InvalidHost::*; | ||
use super::Validator; | ||
use std::{fmt, num::ParseIntError}; | ||
use url::{Host, ParseError}; | ||
|
||
/// A validator for the host of a URL. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct HostValidator; | ||
|
||
/// An error for the host validation. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum InvalidHost { | ||
/// Invalid port. | ||
InvalidPort(ParseIntError), | ||
/// Invalid hostname. | ||
InvalidHostname(ParseError), | ||
} | ||
|
||
impl fmt::Display for InvalidHost { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
InvalidPort(err) => write!(f, "invalid port: {err}"), | ||
InvalidHostname(err) => write!(f, "invalid hostname: {err}"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for InvalidHost {} | ||
|
||
impl Validator<str> for HostValidator { | ||
type Error = InvalidHost; | ||
|
||
#[inline] | ||
fn validate(&self, data: &str) -> Result<(), Self::Error> { | ||
if let Some((hostname, port)) = data.rsplit_once(':') { | ||
if let Err(err) = port.parse::<u16>() { | ||
Err(InvalidPort(err)) | ||
} else if let Err(err) = Host::parse(hostname) { | ||
Err(InvalidHostname(err)) | ||
} else { | ||
Ok(()) | ||
} | ||
} else if let Err(err) = Host::parse(data) { | ||
Err(InvalidHostname(err)) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use super::Validator; | ||
use url::{Host, ParseError}; | ||
|
||
/// A validator for the hostname of a URL. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct HostnameValidator; | ||
|
||
impl Validator<str> for HostnameValidator { | ||
type Error = ParseError; | ||
|
||
#[inline] | ||
fn validate(&self, data: &str) -> Result<(), Self::Error> { | ||
Host::parse(data)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::Validator; | ||
use std::{ | ||
net::{AddrParseError, IpAddr}, | ||
str::FromStr, | ||
}; | ||
|
||
/// A validator for [`IpAddr`]. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct IpAddrValidator; | ||
|
||
impl Validator<str> for IpAddrValidator { | ||
type Error = AddrParseError; | ||
|
||
#[inline] | ||
fn validate(&self, data: &str) -> Result<(), Self::Error> { | ||
IpAddr::from_str(data)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters