Complete module privacy refactor

This commit is contained in:
Daniel Sockwell 2020-04-21 14:38:32 -04:00
parent 1136e2b8de
commit 33e1526556
33 changed files with 56 additions and 51 deletions

View File

@ -43,6 +43,14 @@ pub use err::Error;
pub mod config;
mod err;
mod event;
pub mod request;
pub mod response;
/// A user ID.
///
/// Internally, Mastodon IDs are i64s, but are sent to clients as string because
/// JavaScript numbers don't support i64s. This newtype serializes to/from a string, but
/// keeps the i64 as the "true" value for internal use.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[doc(hidden)]
pub struct Id(pub i64);

View File

@ -3,16 +3,15 @@ mod postgres;
mod query;
mod timeline;
pub mod err;
mod err;
mod subscription;
pub(crate) use err::Error;
pub use err::{Error, Timeline as TimelineErr};
pub use subscription::{Blocks, Subscription};
#[doc(hidden)]
pub use timeline::Timeline;
use timeline::{Content, Reach, Stream};
use self::postgres::PgPool;
pub use self::postgres::PgPool;
use self::query::Query;
use crate::config::Postgres;
use warp::filters::BoxedFilter;

View File

@ -2,7 +2,7 @@
use super::err;
use super::timeline::{Scope, UserData};
use crate::config;
use crate::event::Id;
use crate::Id;
use ::postgres;
use hashbrown::HashSet;

View File

@ -8,7 +8,7 @@
use super::postgres::PgPool;
use super::query::Query;
use super::{Content, Reach, Stream, Timeline};
use crate::event::Id;
use crate::Id;
use hashbrown::HashSet;

View File

@ -1,5 +1,5 @@
use super::Error;
use crate::event::Id;
use crate::Id;
use hashbrown::HashSet;
use std::convert::TryFrom;

View File

@ -1,9 +1,13 @@
//! Stream the updates appropriate for a given `User`/`timeline` pair from Redis.
pub use crate::event::Event;
pub use event::Event;
pub use redis::Manager as RedisManager;
pub use stream::{Sse as SseStream, Ws as WsStream};
pub(self) use event::err::Event as EventErr;
pub(self) use event::Payload;
pub(crate) mod event;
mod redis;
mod stream;

View File

@ -1,12 +1,10 @@
mod checked_event;
mod dynamic_event;
mod err;
pub(crate) use checked_event::Id;
pub(crate) use err::EventErr;
pub mod err;
use self::checked_event::CheckedEvent;
use self::dynamic_event::{DynEvent, EventKind};
use crate::Id;
use hashbrown::HashSet;
use serde::Serialize;
@ -119,14 +117,14 @@ impl Event {
}
impl TryFrom<String> for Event {
type Error = EventErr;
type Error = err::Event;
fn try_from(event_txt: String) -> Result<Event, Self::Error> {
Event::try_from(event_txt.as_str())
}
}
impl TryFrom<&str> for Event {
type Error = EventErr;
type Error = err::Event;
fn try_from(event_txt: &str) -> Result<Event, Self::Error> {
match serde_json::from_str(event_txt) {

View File

@ -13,7 +13,6 @@ mod visibility;
pub(self) use super::Payload;
pub(super) use announcement_reaction::AnnouncementReaction;
pub(crate) use id::Id;
pub(crate) use status::Status;
use announcement::Announcement;

View File

@ -1,4 +1,5 @@
use super::{emoji::Emoji, id::Id, visibility::Visibility};
use super::{emoji::Emoji, visibility::Visibility};
use crate::Id;
use serde::{Deserialize, Serialize};
#[serde(deny_unknown_fields)]

View File

@ -1,4 +1,5 @@
use super::super::EventErr;
use super::super::err;
use crate::Id;
use serde::{
de::{self, Visitor},
@ -7,19 +8,11 @@ use serde::{
use serde_json::Value;
use std::{convert::TryFrom, fmt, num::ParseIntError, str::FromStr};
/// A user ID.
///
/// Internally, Mastodon IDs are i64s, but are sent to clients as string because
/// JavaScript numbers don't support i64s. This newtype serializes to/from a string, but
/// keeps the i64 as the "true" value for internal use.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Id(pub i64);
impl TryFrom<&Value> for Id {
type Error = EventErr;
type Error = err::Event;
fn try_from(v: &Value) -> Result<Self, Self::Error> {
Ok(v.as_str().ok_or(EventErr::DynParse)?.parse()?)
Ok(v.as_str().ok_or(err::Event::DynParse)?.parse()?)
}
}

View File

@ -1,4 +1,4 @@
use super::id::Id;
use crate::Id;
use serde::{Deserialize, Serialize};
#[serde(deny_unknown_fields)]

View File

@ -5,11 +5,11 @@ mod poll;
use super::account::Account;
use super::emoji::Emoji;
use super::id::Id;
use super::mention::Mention;
use super::tag::Tag;
use super::visibility::Visibility;
use super::Payload;
use crate::Id;
use application::Application;
use attachment::Attachment;
use card::Card;

View File

@ -1,5 +1,6 @@
use super::err;
use super::Payload;
use super::{EventErr, Id};
use crate::Id;
use std::convert::TryFrom;
@ -38,7 +39,7 @@ pub(crate) struct DynStatus {
pub(crate) boosted_user: Option<Id>,
}
type Result<T> = std::result::Result<T, EventErr>;
type Result<T> = std::result::Result<T, err::Event>;
impl DynEvent {
pub(crate) fn set_update(self) -> Result<Self> {
@ -52,13 +53,11 @@ impl DynEvent {
}
impl DynStatus {
pub(crate) fn new(payload: &Value) -> Result<Self> {
use EventErr::*;
Ok(Self {
id: Id::try_from(&payload["account"]["id"])?,
username: payload["account"]["acct"]
.as_str()
.ok_or(DynParse)?
.ok_or(err::Event::DynParse)?
.to_string(),
language: payload["language"].as_str().map(String::from),
mentioned_users: HashSet::new(),

View File

@ -1,17 +1,17 @@
use std::{fmt, num::ParseIntError};
#[derive(Debug)]
pub enum EventErr {
pub enum Event {
SerdeParse(serde_json::Error),
NonNumId(ParseIntError),
DynParse,
}
impl std::error::Error for EventErr {}
impl std::error::Error for Event {}
impl fmt::Display for EventErr {
impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use EventErr::*;
use Event::*;
match self {
SerdeParse(inner) => write!(f, "{}", inner),
NonNumId(inner) => write!(f, "ID could not be parsed: {}", inner),
@ -21,12 +21,12 @@ impl fmt::Display for EventErr {
}
}
impl From<ParseIntError> for EventErr {
impl From<ParseIntError> for Event {
fn from(error: ParseIntError) -> Self {
Self::NonNumId(error)
}
}
impl From<serde_json::Error> for EventErr {
impl From<serde_json::Error> for Event {
fn from(error: serde_json::Error) -> Self {
Self::SerdeParse(error)
}

View File

@ -2,6 +2,7 @@ mod connection;
mod manager;
mod msg;
pub(self) use super::{Event, EventErr};
pub(self) use connection::RedisConn;
pub use manager::Error;
pub use manager::Manager;

View File

@ -3,9 +3,9 @@ pub(crate) use err::RedisConnErr;
use super::msg::{RedisParseErr, RedisParseOutput};
use super::Error as ManagerErr;
use super::Event;
use super::RedisCmd;
use crate::config::Redis;
use crate::event::Event;
use crate::request::Timeline;
use futures::{Async, Poll};

View File

@ -9,7 +9,7 @@ pub enum RedisConnErr {
IncorrectPassword(String),
MissingPassword,
NotRedis(String),
TimelineErr(request::err::Timeline),
TimelineErr(request::TimelineErr),
}
impl RedisConnErr {
@ -57,8 +57,8 @@ impl fmt::Display for RedisConnErr {
}
}
impl From<request::err::Timeline> for RedisConnErr {
fn from(e: request::err::Timeline) -> RedisConnErr {
impl From<request::TimelineErr> for RedisConnErr {
fn from(e: request::TimelineErr) -> RedisConnErr {
RedisConnErr::TimelineErr(e)
}
}

View File

@ -4,11 +4,13 @@
mod err;
pub use err::Error;
use super::Event;
use super::{RedisCmd, RedisConn};
use crate::config;
use crate::event::Event;
use crate::request::{Subscription, Timeline};
pub(self) use super::EventErr;
use futures::{Async, Stream as _Stream};
use hashbrown::HashMap;
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};

View File

@ -1,7 +1,6 @@
use super::super::{RedisConnErr, RedisParseErr};
use crate::event::{Event, EventErr};
use crate::request::err::Timeline as TimelineErr;
use crate::request::Timeline;
use super::{Event, EventErr};
use crate::request::{Timeline, TimelineErr};
use std::fmt;
#[derive(Debug)]

View File

@ -1,5 +1,7 @@
pub use sse::Sse;
pub use ws::Ws;
pub(self) use super::{Event, Payload};
mod sse;
mod ws;

View File

@ -1,4 +1,4 @@
use crate::event::{Event, Payload};
use super::{Event, Payload};
use crate::request::{Subscription, Timeline};
use futures::stream::Stream;

View File

@ -1,4 +1,4 @@
use crate::event::{Event, Payload};
use super::{Event, Payload};
use crate::request::{Subscription, Timeline};
use futures::{future::Future, stream::Stream};