Lightweight Usage
Lightweight usage means using the Rix facade while enabling only the packages you need.
The normal facade include is:
#include <rix.hpp>By default, this exposes the available mounted modules:
rix.auth
rix.csv
rix.debug
rix.pdfFor many applications, that is the simplest choice.
When you want a smaller facade, define feature macros before including rix.hpp.
Basic idea
Feature macros control which packages are mounted into the global rix object.
Example with Auth only:
#define RIX_ENABLE_AUTH
#include <rix.hpp>
int main()
{
auto auth = rix.auth.memory();
return 0;
}In this file, the facade exposes:
rix.authIt does not expose:
rix.csv
rix.debug
rix.pdfunless those modules are enabled too.
Why use lightweight mode
Use lightweight mode when:
- one example only needs one package
- a small tool does not need the full facade
- a library wants clearer compile boundaries
- a project wants to avoid unnecessary includes
- you want to make package usage explicit
The public API still stays clean:
rix.auth.memory()The difference is that only selected modules are mounted.
Available macros
The current facade supports:
RIX_ENABLE_AUTH
RIX_ENABLE_CSV
RIX_ENABLE_DEBUG
RIX_ENABLE_PDF| Macro | Mounted API |
|---|---|
RIX_ENABLE_AUTH | rix.auth |
RIX_ENABLE_CSV | rix.csv |
RIX_ENABLE_DEBUG | rix.debug |
RIX_ENABLE_PDF | rix.pdf |
Auth-only example
Create a small file:
mkdir -p ~/rix-lightweight-auth
cd ~/rix-lightweight-auth
touch auth.cppAdd:
#define RIX_ENABLE_AUTH
#include <rix.hpp>
int main()
{
auto auth = rix.auth.memory();
auto registered = auth.register_user({"ada@example.com","correct-password"});
if (registered.failed())
{
return 1;
}
auto login = auth.login({"ada@example.com", "correct-password"});
return login.failed() ? 1 : 0;
}Run it:
vix run auth.cppIf Rix is not available yet for single-file usage, install the facade globally:
vix install -g rix/rixThen run again:
vix run auth.cppAuth with Debug
Many examples need Auth plus debug output.
Enable both modules:
#define RIX_ENABLE_AUTH
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
rix.debug.print("Rix Auth lightweight example");
auto auth = rix.auth.memory();
auto registered = auth.register_user({
"ada@example.com",
"correct-password"
});
if (registered.failed())
{
const auto &error = registered.error();
rix.debug.eprint(
"auth error:",
rix.auth.error.to_string(error),
error.message()
);
return 1;
}
rix.debug.print("registered:", registered.value().email());
return 0;
}Use rix.debug for lightweight debug output, formatting, printing, and inspection.
For application logging, prefer the Vix logging system.
CSV-only example
Enable only CSV:
#define RIX_ENABLE_CSV
#include <rix.hpp>
int main()
{
auto table = rix.csv.parse(
"name,language\n"
"Ada,C++\n"
"Gaspard,Vix.cpp\n"
);
auto output = rix.csv.write(table);
return output.empty() ? 1 : 0;
}This exposes:
rix.csvbut not:
rix.auth
rix.debug
rix.pdfCSV with Debug
For examples that print the parsed result:
#define RIX_ENABLE_CSV
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
auto table = rix.csv.parse(
"name,language\n"
"Ada,C++\n"
"Gaspard,Vix.cpp\n"
);
rix.debug.print("rows:", table.size());
return 0;
}PDF-only example
Enable only PDF:
#define RIX_ENABLE_PDF
#include <rix.hpp>
int main()
{
auto doc = rix.pdf.document();
auto &page = doc.add_page();
page.text(
page.x_left(),
page.y_top(),
"Hello from rix.pdf"
);
auto saved = rix.pdf.save(doc, "hello.pdf");
return saved.failed() ? 1 : 0;
}This exposes:
rix.pdfPDF with Debug
PDF examples often need debug output for errors:
#define RIX_ENABLE_PDF
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
auto doc = rix.pdf.document();
auto &page = doc.add_page();
page.text(
page.x_left(),
page.y_top(),
"Hello from rix.pdf"
);
auto saved = rix.pdf.save(doc, "hello.pdf");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message()
);
return 1;
}
rix.debug.print("created:", "hello.pdf");
return 0;
}Use lightweight mode in a project
Inside a Vix project, add the facade package:
vix add rix/rix
vix installThen declare it in vix.app:
deps = [
"rix/rix",
]Use feature macros in your C++ files:
#define RIX_ENABLE_AUTH
#define RIX_ENABLE_DEBUG
#include <rix.hpp>Build and run:
vix build
vix runUse a shared project header
If several files need the same lightweight facade shape, create a small project header.
Example:
include/app/rix.hpp#pragma once
#define RIX_ENABLE_AUTH
#define RIX_ENABLE_DEBUG
#include <rix.hpp>Then use it from application code:
#include <app/rix.hpp>
int main()
{
rix.debug.print("App Rix facade ready");
auto auth = rix.auth.memory();
return 0;
}This keeps the selected modules consistent across the project.
Lightweight mode and dependencies
Feature macros do not install packages.
They only control what is mounted into the rix object.
This controls facade mounting:
#define RIX_ENABLE_AUTH
#include <rix.hpp>This controls project dependencies:
deps = [
"rix/rix",
]You need the dependency installed and available before the code can compile.
Lightweight facade vs independent packages
Lightweight facade usage still uses:
#include <rix.hpp>and:
rix.authIndependent package usage uses a package header instead:
#include <rix/auth.hpp>and lower-level package APIs.
Use lightweight facade when you still want the rix.* public style.
Use independent packages when you want direct package-level control and do not need the unified facade.
Common mistakes
Defining macros after the include
Wrong:
#include <rix.hpp>
#define RIX_ENABLE_AUTHCorrect:
#define RIX_ENABLE_AUTH
#include <rix.hpp>Feature macros must be defined before including rix.hpp.
Using a module that was not enabled
This will not work:
#define RIX_ENABLE_AUTH
#include <rix.hpp>
int main()
{
rix.debug.print("hello");
}Enable Debug too:
#define RIX_ENABLE_AUTH
#define RIX_ENABLE_DEBUG
#include <rix.hpp>Forgetting the project dependency
This is not enough:
#define RIX_ENABLE_AUTH
#include <rix.hpp>In a vix.app project, declare the facade dependency:
deps = [
"rix/rix",
]Then run:
vix installWhat you should remember
Default facade:
#include <rix.hpp>Lightweight facade:
#define RIX_ENABLE_AUTH
#include <rix.hpp>Available macros:
RIX_ENABLE_AUTH
RIX_ENABLE_CSV
RIX_ENABLE_DEBUG
RIX_ENABLE_PDFFeature macros must come before #include <rix.hpp>.
Project dependencies still go in vix.app:
deps = [
"rix/rix",
]Next step
Continue with the facade API overview.
Next: Facade API