mirror of https://github.com/djcb/mu.git
lib: improve printability for some types
A little fmt pixie dust
This commit is contained in:
parent
264bb092f0
commit
89ed21e0c5
|
@ -207,7 +207,10 @@ struct Field {
|
|||
}
|
||||
};
|
||||
|
||||
static inline bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; }
|
||||
// equality
|
||||
static inline constexpr bool operator==(const Field& f1, const Field& f2) { return f1.id == f2.id; }
|
||||
static inline constexpr bool operator==(const Field& f1, const Field::Id id) { return f1.id == id; }
|
||||
|
||||
|
||||
MU_ENABLE_BITOPS(Field::Flag);
|
||||
|
||||
|
@ -594,20 +597,5 @@ Option<Field> field_from_number(size_t id)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a fmt-printable representation of Field for fmt
|
||||
*
|
||||
* @param field a Field
|
||||
*
|
||||
* @return a printable representation
|
||||
*/
|
||||
static inline constexpr auto format_as(const Field& field) {
|
||||
return field.name;
|
||||
}
|
||||
static inline constexpr auto format_as(const Field::Id id) {
|
||||
return format_as(field_from_id(id));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Mu
|
||||
#endif /* MU_FIELDS_HH__ */
|
||||
|
|
|
@ -467,6 +467,13 @@ private:
|
|||
MU_ENABLE_BITOPS(Store::Options);
|
||||
MU_ENABLE_BITOPS(Store::MoveOptions);
|
||||
|
||||
static inline std::string
|
||||
format_as(const Store& store)
|
||||
{
|
||||
return mu_format("store ({}/{})", format_as(store.xapian_db()),
|
||||
store.root_maildir());
|
||||
}
|
||||
|
||||
} // namespace Mu
|
||||
|
||||
#endif /* __MU_STORE_HH__ */
|
||||
|
|
|
@ -101,4 +101,6 @@ XapianDb::XapianDb(const std::string& db_path, Flavor flavor) :
|
|||
|
||||
if (flavor == Flavor::CreateOverwrite)
|
||||
set_timestamp(MetadataIface::created_key);
|
||||
|
||||
mu_debug("created {} / {}", flavor, *this);
|
||||
}
|
||||
|
|
|
@ -192,6 +192,16 @@ public:
|
|||
*/
|
||||
const std::string& path() const;
|
||||
|
||||
/**
|
||||
* Get a description of the Xapian database
|
||||
*
|
||||
* @return description
|
||||
*/
|
||||
const std::string description() const {
|
||||
return db().get_description();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of documents (messages) in the database
|
||||
*
|
||||
|
@ -399,6 +409,27 @@ private:
|
|||
DbType db_;
|
||||
};
|
||||
|
||||
constexpr std::string_view
|
||||
format_as(XapianDb::Flavor flavor)
|
||||
{
|
||||
switch(flavor) {
|
||||
case XapianDb::Flavor::CreateOverwrite:
|
||||
return "create-overwrite";
|
||||
case XapianDb::Flavor::Open:
|
||||
return "open";
|
||||
case XapianDb::Flavor::ReadOnly:
|
||||
return "read-only";
|
||||
default:
|
||||
return "??";
|
||||
}
|
||||
}
|
||||
|
||||
static inline std::string
|
||||
format_as(const XapianDb& db)
|
||||
{
|
||||
return mu_format("{} @ {}", db.description(), db.path());
|
||||
}
|
||||
|
||||
} // namespace Mu
|
||||
|
||||
#endif /* MU_XAPIAN_DB_HH__ */
|
||||
|
|
Loading…
Reference in New Issue