module Ecluse.Core.Registry.Cargo.Source (
CargoSource,
parseSource,
sourceComparisonKey,
) where
import Data.Char (isControl, isDigit, isSpace)
import Data.IP (IPv6)
import Data.Text qualified as T
import Network.URI qualified as URI
import Ecluse.Core.Registry (ParseError (..))
import Ecluse.Core.Text (readDecimalText, readHexText)
newtype CargoSource = CargoSource Text
deriving stock (CargoSource -> CargoSource -> Bool
(CargoSource -> CargoSource -> Bool)
-> (CargoSource -> CargoSource -> Bool) -> Eq CargoSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CargoSource -> CargoSource -> Bool
== :: CargoSource -> CargoSource -> Bool
$c/= :: CargoSource -> CargoSource -> Bool
/= :: CargoSource -> CargoSource -> Bool
Eq, Eq CargoSource
Eq CargoSource =>
(CargoSource -> CargoSource -> Ordering)
-> (CargoSource -> CargoSource -> Bool)
-> (CargoSource -> CargoSource -> Bool)
-> (CargoSource -> CargoSource -> Bool)
-> (CargoSource -> CargoSource -> Bool)
-> (CargoSource -> CargoSource -> CargoSource)
-> (CargoSource -> CargoSource -> CargoSource)
-> Ord CargoSource
CargoSource -> CargoSource -> Bool
CargoSource -> CargoSource -> Ordering
CargoSource -> CargoSource -> CargoSource
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CargoSource -> CargoSource -> Ordering
compare :: CargoSource -> CargoSource -> Ordering
$c< :: CargoSource -> CargoSource -> Bool
< :: CargoSource -> CargoSource -> Bool
$c<= :: CargoSource -> CargoSource -> Bool
<= :: CargoSource -> CargoSource -> Bool
$c> :: CargoSource -> CargoSource -> Bool
> :: CargoSource -> CargoSource -> Bool
$c>= :: CargoSource -> CargoSource -> Bool
>= :: CargoSource -> CargoSource -> Bool
$cmax :: CargoSource -> CargoSource -> CargoSource
max :: CargoSource -> CargoSource -> CargoSource
$cmin :: CargoSource -> CargoSource -> CargoSource
min :: CargoSource -> CargoSource -> CargoSource
Ord, Int -> CargoSource -> ShowS
[CargoSource] -> ShowS
CargoSource -> String
(Int -> CargoSource -> ShowS)
-> (CargoSource -> String)
-> ([CargoSource] -> ShowS)
-> Show CargoSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CargoSource -> ShowS
showsPrec :: Int -> CargoSource -> ShowS
$cshow :: CargoSource -> String
show :: CargoSource -> String
$cshowList :: [CargoSource] -> ShowS
showList :: [CargoSource] -> ShowS
Show)
parseSource :: Text -> Either ParseError CargoSource
parseSource :: Text -> Either ParseError CargoSource
parseSource Text
source = do
parsed <- Either ParseError URI
-> (URI -> Either ParseError URI)
-> Maybe URI
-> Either ParseError URI
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either ParseError URI
forall a. Either ParseError a
malformed URI -> Either ParseError URI
forall a b. b -> Either a b
Right (String -> Maybe URI
URI.parseURI (Text -> String
forall a. ToString a => a -> String
toString Text
source))
authority <- maybe malformed Right (URI.uriAuthority parsed)
let scheme = Text -> Text
T.toLower (Int -> Text -> Text
T.dropEnd Int
1 (String -> Text
forall a. ToText a => a -> Text
toText (URI -> String
URI.uriScheme URI
parsed)))
sparse = Text
"sparse+" Text -> Text -> Bool
`T.isPrefixOf` Text
scheme
special = Text
scheme Text -> [Text] -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Text
"http", Text
"https", Text
"ws", Text
"wss", Text
"ftp", Text
"file"]
rawHost = String -> Text
forall a. ToText a => a -> Text
toText (URIAuth -> String
URI.uriRegName URIAuth
authority)
hostText = if Bool
special then Text -> Text
T.toLower (String -> Text
forall a. ToText a => a -> Text
toText (ShowS
URI.unEscapeString (Text -> String
forall a. ToString a => a -> String
toString Text
rawHost))) else Text
rawHost
hostname <- case T.stripPrefix "[" hostText >>= T.stripSuffix "]" of
Just Text
address -> Either ParseError Text
-> (IPv6 -> Either ParseError Text)
-> Maybe IPv6
-> Either ParseError Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either ParseError Text
forall a. Either ParseError a
malformed (\IPv6
value -> Text -> Either ParseError Text
forall a b. b -> Either a b
Right (Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IPv6 -> Text
forall b a. (Show a, IsString b) => a -> b
show (IPv6
value :: IPv6) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]")) (String -> Maybe IPv6
forall a. Read a => String -> Maybe a
readMaybe (Text -> String
forall a. ToString a => a -> String
toString Text
address))
Maybe Text
Nothing -> do
Bool -> Either ParseError () -> Either ParseError ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ((Char -> Bool) -> Text -> Bool
T.any (\Char
char -> Char -> Bool
isControl Char
char Bool -> Bool -> Bool
|| Char -> Bool
isSpace Char
char Bool -> Bool -> Bool
|| Char
char Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Char
'/', Char
'\\', Char
'?', Char
'#', Char
'@', Char
':', Char
'[', Char
']', Char
'<', Char
'>', Char
'^', Char
'|', Char
'%']) Text
hostText Bool -> Bool -> Bool
&& Bool
special) Either ParseError ()
forall a. Either ParseError a
malformed
if Bool
special then Text -> Either ParseError Text
specialHost Text
hostText else Text -> Either ParseError Text
forall a. a -> Either ParseError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
hostText
let github = Bool -> Bool
not (Text
"+" Text -> Text -> Bool
`T.isInfixOf` Text
scheme) Bool -> Bool -> Bool
&& Text
hostname Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"github.com"
canonicalScheme = if Bool
github then Text
"https" else Text
scheme
when ("+" `T.isInfixOf` scheme && not sparse) malformed
when (T.null hostname && scheme /= "file") malformed
writtenPort <- parsePort (toText (URI.uriPort authority))
let nativePort = Maybe Int
writtenPort Maybe Int -> (Int -> Maybe Int) -> Maybe Int
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
value -> Int
value Int -> Maybe () -> Maybe Int
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
value Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Text -> Maybe Int
defaultPort Text
scheme)
canonicalPort = Maybe Int
nativePort Maybe Int -> (Int -> Maybe Int) -> Maybe Int
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
value -> Int
value Int -> Maybe () -> Maybe Int
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
value Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Text -> Maybe Int
defaultPort Text
canonicalScheme)
dotSegment Text
segment = case Text -> Text
T.toLower Text
segment of
Text
"%2e" -> Text
"."
Text
"%2e%2e" -> Text
".."
Text
".%2e" -> Text
".."
Text
"%2e." -> Text
".."
Text
_ -> Text
segment
originalPath = String -> Text
forall a. ToText a => a -> Text
toText (URI -> String
URI.uriPath URI
parsed)
path = if Bool
special Bool -> Bool -> Bool
&& Text -> Bool
T.null Text
originalPath then Text
"/" else Text
originalPath
dotPath = Text -> [Text] -> Text
T.intercalate Text
"/" ((Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
dotSegment (HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
T.splitOn Text
"/" Text
path))
withDots = URI
parsed{URI.uriPath = toString dotPath}
normalised <- maybe malformed Right (URI.parseURI (URI.normalizePathSegments (URI.uriToString id withDots "")))
let normalPath = String -> Text
forall a. ToText a => a -> Text
toText (URI -> String
URI.uriPath URI
normalised)
trimmed = if Text
normalPath Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"/" then Text
normalPath else Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
normalPath (Text -> Text -> Maybe Text
T.stripSuffix Text
"/" Text
normalPath)
casePath = if Bool
github then Text -> Text
T.toLower Text
trimmed else Text
trimmed
canonicalPath = if Bool
sparse then Text
casePath else Text -> Text
gitPath Text
casePath
canonicalAuthority = URIAuth
authority{URI.uriRegName = toString hostname, URI.uriPort = maybe "" ((":" <>) . show) canonicalPort}
canonical = URI
parsed{URI.uriScheme = toString (canonicalScheme <> ":"), URI.uriAuthority = Just canonicalAuthority, URI.uriPath = toString canonicalPath}
text = String -> Text
forall a. ToText a => a -> Text
toText (ShowS -> URI -> ShowS
URI.uriToString ShowS
forall a. a -> a
id URI
canonical String
"")
cratesIo = (Bool -> Bool
not Bool
sparse Bool -> Bool -> Bool
&& Text
text Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"https://github.com/rust-lang/crates.io-index") Bool -> Bool -> Bool
|| (Bool
sparse Bool -> Bool -> Bool
&& Text
text Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"sparse+https://index.crates.io/")
pure (CargoSource (if cratesIo then "crates.io" else (if sparse then "sparse|" else "registry|") <> text))
sourceComparisonKey :: CargoSource -> Text
sourceComparisonKey :: CargoSource -> Text
sourceComparisonKey (CargoSource Text
key) = Text
key
gitPath :: Text -> Text
gitPath :: Text -> Text
gitPath Text
path = case Text -> Text -> Maybe Text
T.stripSuffix Text
".git" Text
path of
Maybe Text
Nothing -> Text
path
Just Text
shortened ->
let (Text
prefix, Text
segment) = HasCallStack => Text -> Text -> (Text, Text)
Text -> Text -> (Text, Text)
T.breakOnEnd Text
"/" Text
shortened
parent :: Text
parent = if Text
prefix Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"/" then Text
prefix else Int -> Text -> Text
T.dropEnd Int
1 Text
prefix
unchanged :: Char -> Bool
unchanged Char
char = Char
char Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
> Char
' ' Bool -> Bool -> Bool
&& Char
char Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
< Char
'\DEL' Bool -> Bool -> Bool
&& Char
char Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`notElem` [Char
'"', Char
'#', Char
'<', Char
'>', Char
'?', Char
'^', Char
'`', Char
'{', Char
'}', Char
'/', Char
'%', Char
'\\']
in if Text
segment Text -> [Text] -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Text
".", Text
".."]
then Text
parent
else Text
prefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a. ToText a => a -> Text
toText ((Char -> Bool) -> ShowS
URI.escapeURIString Char -> Bool
unchanged (Text -> String
forall a. ToString a => a -> String
toString Text
segment))
specialHost :: Text -> Either ParseError Text
specialHost :: Text -> Either ParseError Text
specialHost Text
host =
let withoutDot :: Text
withoutDot = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
host (Text -> Text -> Maybe Text
T.stripSuffix Text
"." Text
host)
lastPart :: Text
lastPart = (Char -> Bool) -> Text -> Text
T.takeWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'.') Text
withoutDot
numeric :: Bool
numeric = (Bool -> Bool
not (Text -> Bool
T.null Text
lastPart) Bool -> Bool -> Bool
&& (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
lastPart) Bool -> Bool -> Bool
|| Maybe (Int, Text) -> Bool
forall a. Maybe a -> Bool
isJust (Text -> Maybe (Int, Text)
ipv4Digits Text
lastPart)
in if Bool
numeric then [Text] -> Either ParseError Text
ipv4Host (HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
T.splitOn Text
"." Text
withoutDot) else Text -> Either ParseError Text
forall a b. b -> Either a b
Right Text
host
ipv4Host :: [Text] -> Either ParseError Text
ipv4Host :: [Text] -> Either ParseError Text
ipv4Host [Text]
parts = do
Bool -> Either ParseError () -> Either ParseError ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Text] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
parts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
4) Either ParseError ()
forall a. Either ParseError a
malformed
numbers <- (Text -> Either ParseError Integer)
-> [Text] -> Either ParseError [Integer]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Text -> Either ParseError Integer
ipv4Number [Text]
parts
case reverse numbers of
Integer
final : [Integer]
reversedPrefix -> do
let prefix :: [Integer]
prefix = [Integer] -> [Integer]
forall a. [a] -> [a]
reverse [Integer]
reversedPrefix
finalWidth :: Int
finalWidth = Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
- [Integer] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Integer]
prefix
Bool -> Either ParseError () -> Either ParseError ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ((Integer -> Bool) -> [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
255) [Integer]
prefix Bool -> Bool -> Bool
|| Integer
final Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
256 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
finalWidth) Either ParseError ()
forall a. Either ParseError a
malformed
let address :: Integer
address = (Integer -> Integer -> Integer) -> Integer -> [Integer] -> Integer
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Integer
total Integer
byte -> Integer
total Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
256 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
byte) Integer
0 [Integer]
prefix Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
256 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
finalWidth Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
final
Text -> Either ParseError Text
forall a. a -> Either ParseError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> [Text] -> Text
T.intercalate Text
"." [Integer -> Text
forall b a. (Show a, IsString b) => a -> b
show (Integer
address Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`div` (Integer
256 Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
power) Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`mod` Integer
256) | Int
power <- [Int
3, Int
2, Int
1, Int
0 :: Int]])
[Integer]
_ -> Either ParseError Text
forall a. Either ParseError a
malformed
ipv4Number :: Text -> Either ParseError Integer
ipv4Number :: Text -> Either ParseError Integer
ipv4Number Text
part = do
(base, digits) <- Either ParseError (Int, Text)
-> ((Int, Text) -> Either ParseError (Int, Text))
-> Maybe (Int, Text)
-> Either ParseError (Int, Text)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either ParseError (Int, Text)
forall a. Either ParseError a
malformed (Int, Text) -> Either ParseError (Int, Text)
forall a b. b -> Either a b
Right (Text -> Maybe (Int, Text)
ipv4Digits Text
part)
let width = case Int
base of
Int
16 -> Int
8
Int
8 -> Int
11
Int
_ -> Int
10
when (T.compareLength digits width == GT) malformed
number <-
if T.null digits
then Right 0
else maybe malformed Right $ case base of
Int
16 -> Text -> Maybe Integer
forall a. Integral a => Text -> Maybe a
readHexText Text
digits
Int
8 -> String -> Maybe Integer
forall a. Read a => String -> Maybe a
readMaybe (String
"0o" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. ToString a => a -> String
toString Text
digits)
Int
_ -> Text -> Maybe Integer
forall a. Integral a => Text -> Maybe a
readDecimalText Text
digits
if number <= toInteger (maxBound :: Word32) then Right number else malformed
ipv4Digits :: Text -> Maybe (Int, Text)
ipv4Digits :: Text -> Maybe (Int, Text)
ipv4Digits Text
part = do
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Text -> Bool
T.null Text
part))
let (Int
base, Text
digits)
| Just Text
rest <- Text -> Text -> Maybe Text
T.stripPrefix Text
"0x" Text
part Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Text -> Maybe Text
T.stripPrefix Text
"0X" Text
part = (Int
16, Text
rest)
| Text -> Int -> Ordering
T.compareLength Text
part Int
2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
LT, Just Text
rest <- Text -> Text -> Maybe Text
T.stripPrefix Text
"0" Text
part = (Int
8, Text
rest)
| Bool
otherwise = (Int
10, Text
part)
digit :: Char -> Bool
digit Char
char = case Int
base of
Int
16 -> Char -> Bool
isDigit Char
char Bool -> Bool -> Bool
|| Char
char Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Char
'a' .. Char
'f'] Bool -> Bool -> Bool
|| Char
char Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Char
'A' .. Char
'F']
Int
8 -> Char
char Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Char
'0' .. Char
'7']
Int
_ -> Char -> Bool
isDigit Char
char
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
digit Text
digits)
(Int, Text) -> Maybe (Int, Text)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
base, (Char -> Bool) -> Text -> Text
T.dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'0') Text
digits)
parsePort :: Text -> Either ParseError (Maybe Int)
parsePort :: Text -> Either ParseError (Maybe Int)
parsePort Text
"" = Maybe Int -> Either ParseError (Maybe Int)
forall a b. b -> Either a b
Right Maybe Int
forall a. Maybe a
Nothing
parsePort Text
":" = Maybe Int -> Either ParseError (Maybe Int)
forall a b. b -> Either a b
Right Maybe Int
forall a. Maybe a
Nothing
parsePort Text
value = do
number <- Either ParseError Integer
-> (Integer -> Either ParseError Integer)
-> Maybe Integer
-> Either ParseError Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either ParseError Integer
forall a. Either ParseError a
malformed Integer -> Either ParseError Integer
forall a b. b -> Either a b
Right (Text -> Text -> Maybe Text
T.stripPrefix Text
":" Text
value Maybe Text -> (Text -> Maybe Integer) -> Maybe Integer
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Integer
forall a. Integral a => Text -> Maybe a
readDecimalText :: Maybe Integer)
if number <= 65535 then pure (Just (fromInteger number)) else malformed
defaultPort :: Text -> Maybe Int
defaultPort :: Text -> Maybe Int
defaultPort Text
scheme = case Text
scheme of
Text
"http" -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
80
Text
"https" -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
443
Text
"ws" -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
80
Text
"wss" -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
443
Text
"ftp" -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
21
Text
_ -> Maybe Int
forall a. Maybe a
Nothing
malformed :: Either ParseError a
malformed :: forall a. Either ParseError a
malformed = ParseError -> Either ParseError a
forall a b. a -> Either a b
Left (Text -> ParseError
ParseError Text
"Cargo registry source URL is malformed")