First, let’s define a key term: an antigen. It’s the part of an infectious agent that your body recognizes to trigger an immune response, so this can be something like a protein on the outside of a virus.
What a rapid antigen test does is identify antigens in a human sample by flowing that sample over a set of molecules that serve as probes because they can bind to the antigen of interest–if it’s in the sample.
This usually means that the infectious agent has to be exactly that–infectious, because it needs to be viable enough for whole antigen to be present. This is in contrast to detecting the genetic material of an infectious agent like a virus in a sample, because the RNA of a virus (like SARS-CoV-2!) can hang around in a sample for longer than it actually is able to infect a host, simply because of how RNA decays in contrast to something like a protein that would be the antigen on the outside of such a virus.
As for the rapid piece, these tests are relatively quick (usually under 30 minutes) because all the molecular pieces needed for analysis are in the test itself, and there’s no need for sample processing or temperature changes to drive a chemical reaction, for example. By design, if there is antigen in the sample to bind to the “probe” molecules, a simple internal chemical reaction that is already set up and ready to go then displays colors in the form of easy-to-read lines for a quick result!