@@ -10,6 +10,7 @@ enum BlacklistError {
10
10
CrateNotOnBlacklist ( String ) ,
11
11
}
12
12
13
+ /// Returns whether the given name is blacklisted.
13
14
pub fn is_blacklisted ( conn : & Connection , name : & str ) -> Result < bool , Error > {
14
15
let rows = conn. query (
15
16
"SELECT COUNT(*) FROM blacklisted_crates WHERE crate_name = $1;" ,
@@ -20,6 +21,7 @@ pub fn is_blacklisted(conn: &Connection, name: &str) -> Result<bool, Error> {
20
21
Ok ( count != 0 )
21
22
}
22
23
24
+ /// Returns the crate names on the blacklist, sorted ascending.
23
25
pub fn list_crates ( conn : & Connection ) -> Result < Vec < String > , Error > {
24
26
let rows = conn. query (
25
27
"SELECT crate_name FROM blacklisted_crates ORDER BY crate_name asc;" ,
@@ -29,6 +31,7 @@ pub fn list_crates(conn: &Connection) -> Result<Vec<String>, Error> {
29
31
Ok ( rows. into_iter ( ) . map ( |row| row. get ( 0 ) ) . collect ( ) )
30
32
}
31
33
34
+ /// Adds a crate to the blacklist.
32
35
pub fn add_crate ( conn : & Connection , name : & str ) -> Result < ( ) , Error > {
33
36
if is_blacklisted ( conn, name) ? {
34
37
return Err ( BlacklistError :: CrateAlreadyOnBlacklist ( name. into ( ) ) . into ( ) ) ;
@@ -42,6 +45,7 @@ pub fn add_crate(conn: &Connection, name: &str) -> Result<(), Error> {
42
45
Ok ( ( ) )
43
46
}
44
47
48
+ /// Removes a crate from the blacklist.
45
49
pub fn remove_crate ( conn : & Connection , name : & str ) -> Result < ( ) , Error > {
46
50
if !is_blacklisted ( conn, name) ? {
47
51
return Err ( BlacklistError :: CrateNotOnBlacklist ( name. into ( ) ) . into ( ) ) ;
0 commit comments